-
first of all I did some refactoring.
-
For maintaining the backend app we need logger. I used
winston
for this problem. -
There wasn't any error handling. If the app crashes there was no appropriate error response for that. I added default express error handling.
-
We need to validate input from request to protect our APIs. I used
express-validator
. -
I dockerized project for easy deployment.
First of all create .env
file and add snippet code below:
PORT=ADD_YOUR_PORT
DBURL=ADD_YOUR_DB_URL
To add data in database run npm run seed
.
To run the app in production run npm run build
for building. Then run npm run start
to run the app.
To run the app in development npm run dev
.
Run docker build -t app . --build-arg PORT=${YOUR_PORT} --build-arg DBURL=${YOUR_DB_URL}
. It will create docker image. Then run container from image with docker run -dp 8000:8000 app