Built with Express.js 4.18.3
-
Create a
.env
file and add the following:NODE_ENV=<ENV> APP_PORT=<PORT> API_BASE=<VERSIONED_API_BASE_PATH> HEALTHCHECK=<HEALTHCHECK_API_BASE_PATH> MONGO_URI=<DB_CONNECTION_STRING> SECRET_KEY=<YOUR_SECRET> CORS_ORIGIN=<FRONTEND_DOMAIN>
where:
NODE_ENV
=development
orproduction
.APP_PORT
=5000
or any other available port.API_BASE
=/api/v1
.HEALTHCHECK
=http://localhost:5000/api/v1/status
.MONGO_URI
can be found in Atlas.SECRET_KEY
can be generated usingopenssl
.CORS_ORIGIN
must be the domain of the frontend service.
-
Install dependencies:
npm install
-
Run application:
npm run start:dev
Postman can be used to test the APIs before integrating with the front-end. To do so, use the JSON files present in the postman
directory. First import the sbs-api.postman_environment.json
file to ensure the required environment variables are available to the requests. Then, import the sbs-api.postman_collection.json
file to run requests.
If you are not familiar with importing collections and environments to your Postman workspace, refer Data import and export in Postman | Postman Learning Center
Command: npm run build
Docker command: docker build -t <IMAGE>:<TAG> .
Note:
Follow semantic versioning scheme X.Y.Z
for image <TAG>
.
Command: npm run start:prod
Docker command: docker run --name=<CONTAINER_NAME> [-e <ENV_VAR_NAME>=<ENV_VAR_VALUE>] [-v <HOST_PATH>:<CONTAINER_PATH>] -dp <HOST_PORT>:<CONTAINER_PORT> <IMAGE>:<TAG>
Note: Provide environment variables and mount required files using -e
and -v
options. Refer: docker run | Docker Docs