/express-crud-rensyu

API with CRUD, register, and login functionality powered by ExpressJS. Only for rensyu.

Primary LanguageShell

ExpressJS - CRUD API (template)

A goal API powered by ExpressJS, MongoDB, and Mongoose object data modeling (ODM).


To-do list :

  1. Add error handling properly :

[ Will do ]


  1. Display Hostname, IP, etc. :

[ Will do ]


  1. Make use of HelmetJS to enhance security : https://helmetjs.github.io/

[ Done - additional-cors_and_helmetjs branch ]


  1. Use compression library : https://github.com/expressjs/compression

[ Done - additional-compression_lil-http-terminator branch ]


  1. Install logging library (Winston) :

[ On Progress... - additional-winston branch ]


  1. Please add some of best performance practices : https://expressjs.com/en/advanced/best-practice-performance.html

[ Done reading - Looking forward to implement Supervisor (process manager), handle error properly, and learn more about reverse proxy. ]


  1. Explore more regarding healthcheck and graceful shutdown using some libraries : https://expressjs.com/en/advanced/healthcheck-graceful-shutdown.html

[ Done - additional-healthcheck_graceful-shutdown branch ]


  1. Add PM2 as process mmanager :

[ On Progress.. - additional-pm2 branch ]


  1. Add how to handle uncaughtException OR unexpectedErrorHandler & unhandledRejection OR unexpectedErrorHandler : https://github.com/poolapack/payment-formatter/blob/dev/src/index.js

[ Done - additional-compression_lil-http-terminator branch ]


  1. Add CORS : https://github.com/shawn-dsilva/mern-login-signup-component/blob/master/server.js

[ Done - additional-cors_and_helmetjs branch ]


ExpressJS docs: One thing you should NOT DO is to listen for the uncaughtException event, emitted when an exception bubbles all the way back to the event loop. (For more: )

Stackoverflow answer: Also remember that it is not safe to resume normal operation after 'uncaughtException', because the system becomes corrupted :

The correct use of 'uncaughtException' is to perform synchronous cleanup of allocated resources (e.g. file descriptors, handles, etc) before shutting down the process.
  1. Given above, should one listen to uncaughtException event ? Do a research.

[ Done - uncaughtException should be handled. Let the process crash and restart again using an external monitor (process manager) that runs as an another process. Source: NodeJS docs & Heroku ]


  1. Add validation using Joi

[ Will do ]


  1. Prevent bruteforce attack

[ Will do ]


  1. Deploy ExpressJS to Vercel

[ Will do ]


  1. Add multistage Docker build

[ Will do ]


Why do I need "next()" function ?

Read ExpressJS Middleware : https://expressjs.com/en/guide/writing-middleware.html


How to Run

  1. Install dependencies
yarn

  1. Set environment variables in .env
cp .env.example .env

  1. Run the app
yarn dev