Code Monkey home page Code Monkey logo

mern's Introduction

MERN App

Simple database entry app.

Config variables

Backend: ./backend/src/config/

  • DBURL = mongodb://localhost:27017/entries [database address - must match mongo port]
  • CORSOPTIONS = {origin: http://localhost:3000} [allow access from FE - must match App port]
  • PORT = 5001 [server port]

Frontend: ./src/shared/config.ts & ./.env

  • API_ENDPOINT = http://localhost:5001/api/entries [API URL - must match server port]
  • PORT = 3000 [App port]

Initiate DB

Using Docker: docker run -p 27017:27017 --name expressdb -d mongo:latest This will start a mongoDB instance in a container running on port 27017

Without Docker:

Start Backend

  • From /backend run npm i to install packages
  • run npm run app to start the server, or npm run dev for nodemon with live reloading
  • *** The BE runs on port 5001 by default. If this port is in use, you will need to change the BASE_URL in /src/config.ts to match the current port ***

Start Frontend

  • From root, run npm i
  • run npm run start
  • *** The FE runs on port 3000 by default. If this port is in use, you will need to change the CORS origin in /backend/src/config/server.ts to match the current port ***

Build

  • BE: npm run compile
  • FE: npm run build

API endpoints/

All listed parameters are required

ADD ENTRY:

  • /api/entries
  • method: POST
  • body: { title: string; author: string; text: string; date: string; (yyyy-mm-dd) time: string; (hh:mm am/pm) } res: [{ _id: string; title: string; author: string; text: string; date: string; (yyyy-mm-dd) time: string; (hh:mm am/pm) }]

GET ENTRIES:

  • /api/entries
  • method: GET
  • body: n/a
  • res: [ { _id: string; title: string; author: string; text: string; date: string; (yyyy-mm-dd) time: string; (hh:mm am/pm) }, ... ]

UPDATE ENTRY:

  • /api/entries/:id
  • method: PUT
  • body: { title: string; author: string; text: string; date: string; (yyyy-mm-dd) time: string; (hh:mm am/pm) }
  • params: id: string
  • res: [{ _id: string; title: string; author: string; text: string; date: string; (yyyy-mm-dd) time: string; (hh:mm am/pm) }]

DELETE ENTRY:

  • /api/entries/:id
  • method: DELETE
  • body: n/a
  • params: id: string
  • res: [{ message: string }]

GET PDF:

  • /api/entries/:id
  • method: GET
  • body: n/a
  • params: id: string
  • res: string (base64)

Suggestions

It would obviously be preferable to have written tests for the components and api service, had time permitted.
I'd also have liked to refine the error handling, get it production-ready for deployment (move some of the config variables to the .env, run builds, write production instructions, etc.), and there are a couple of magic numbers in the CSS for the form that I'm not happy about.

The form fields currently only have type-checking as basic protection, but next steps should include proper sanitizing to protect against malicious attack entry to the db when submitting data.

For improved user experience, the design should be made fully responsive. The table format is of course not ideal for a narrow screen, so an alternative mobile-first design would be required, perhaps displaying the entries in a series of vertically stacked detail cards. The form fields should also highlight any invalid text entries.

mern's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.