Back-end REST API for www.codever.dev based on Node.js with ExspressJS
This section concerns about the local developemnt
It might happen to have a zombie running nodejs running on the port 3000 when trying to run npm run debug.
Kill the process and try again
lsof -i tcp:3000
kill -9 xxx # where xxx is the process number from the command above
npm run debug # restart the backend server as usualRun the test npm task
npm run test
To run the integration you have to prepare and start the local docker image and node for backend as specified in the main README file.
When ready run the following command
npm run test:integration
The API has an OpenAPI specification available at docs/openapi/openapi.yaml
Based on that a GUI is generated to test the API directly from browser:
We currently use pm2 to start the project in production
PM2 keeps the old Node.js process running until explicitly restarted. After pulling new backend code (e.g. body-parser limit changes), always reload or restart the PM2 process:
pm2 reload pm2-process-cluster.json # zero-downtime reload (preferred)
# or
pm2 restart pm2-process-cluster.json # hard restartExample: The Express body-parser is configured to accept up to 6 MB JSON payloads (
app.js). If you deploy this change but forget to restart PM2, production still runs with the old default limit (100 KB) and larger requests (e.g. Jupyter notebook uploads) will fail with 413 Request Entity Too Large.
If nginx sits in front of the API, its default client_max_body_size of 1 MB
can also reject large requests before they reach Node.js. Add the following to the
nginx server or location block that proxies to the API:
client_max_body_size 6m;Then reload nginx:
sudo nginx -t && sudo systemctl reload nginxUndo local changes if needed:
git fetch
git reset --hard origin/master
## status
pm2 status
## start
pm2 start pm2-process-cluster.json
## restart - kills and restarts the process
pm2 restart pm2-process-cluster.json
## reload - in comparison with "restart", "reload" achieves 0-second-downtime reload
pm2 reload pm2-process-cluster.json
## stop
pm2 stop pm2-process-cluster.json# start
pm2 start pm2-process.json --env production --time
# restart
pm2 restart pm2-process.json --env production --time
# stop
pm2 stop pm2-process.json --env productionCommited is a pm2-process.exammple.json example file
pm2 logs bookmarks.dev-api-node-10.15.0 --lines 1000tail -f n100 ~/projects/bookmarks.dev-bk/backend/log/access.logWhen pm2 start pm2 start pm2-process.json --env production has the status errored, it might help to delete the app id
pm2 delete bookmarks.dev-api-node-10.15.0 and then try again