The documentation for Node Assignment app which does basic CRUD functions on PostgreSQL Database and is automatically deployed using BitBucket Pipelines on a free-tier AWS EC2 server.
Watch the video walkthrough of the assignment here.
- Continous Integration and Deployment using BitBucket Pipelines.
- Uses TypeScript.
- Uses PM2 to manage the nodejs cluster.
- Testing through Jest.
- Does NOT use any ORM framework, only the pg library.
(OPTIONAL) Create a .env
file with the following properties:
-
POSTGRES_USER: The username of the postgres user.
-
POSTGRES_HOST: The connection endpoint of the postgres database.
-
POSTGRES_DATABASE: The name of the postgres database.
-
POSTGRES_PASSWORD: The password of the postgres database.
-
POSTGRES_PORT: The exposed port of the postgres database.
-
PORT (Optional): Sets the HTTP port number of the express app.
Then run the following command:
docker-compose up --build
npm run build
npm run pm2
The api will get exposed at localhost:3000
.
The testing command will the run the test suites and will attempt to do the following:
- A manufacturer can be created
- An equipment can be created
- A relationship between one manufacturer and an equipment can be created
- If a manufacturer is deleted using the REST endpoint, any related equipment will be also automatically deleted.
- Get, delete and update a manufacturer or an equipment.
To run tests, run the following commands:
docker-compose up --build
npm test
PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.
npm run build //build step
npm run pm2
npm run log //pm2 log
npm run monit //pm2 monit
npm run list //pm2 list all
npm run delete //pm2 delete all
npm run restart //pm2 restart all
npm run stop //pm2 stop all
Name | Description |
---|---|
src/ | Source files |
src/controllers | The controllers of the express app |
src/routes/ | Express REST API routes with swagger documentation |
src/utils | Reusable utilises and library source code like a logger |
tests/ | Test suites are placed here |
scripts/ | Bash commands to run the app inside the EC2 Instance |
The Postman Documentation, Curl commands and the API Playground is hosted here.
The app is deployed to EC2 instance using BitBucket Pipelines and AWS CodeDeploy. A new instance of the app is created for each build using pm2. The API is hosted here. The REST endpoints are open for remote testing.