In this project, a sample microservice is developed in Node.JS, which manages messages and provides details about those messages, specifically whether or not a message is a palindrome. This microservice uses MongoDB database for storing messages and it is packaged using docker.
- NoSQL database: MongoDB object data modeling using Mongoose
- Validation: request data validation using express-json-validator-middleware
- Testing: unit and integration tests using Mocha
- CI: with
github actions
- Docker support
- Code coverage: using nyc
- Code quality: with ESLint
- API documentation: with swagger-jsdoc and swagger-ui-express
Architecture image created using https://c4model.com/
- Node.JS > 12.0.0
- Docker Desktop (for Mac and Windows) / Docker Engine (for Linux)
Testing:
# run all tests
npm run docker:test
To run locally:
npm run docker:dev
Linting:
# run ESLint
npm run lint
# fix ESLint errors
npm run lint:fix
Cleanup:
docker-compose down
The environment variables can be found in the .env
file. Following environment variables are defined:
# Port number
PORT=3000
src\
|--config\ # configurations
|--controllers\ # Route controllers (controller layer)
|--docs\ # Swagger files
|--middlewares\ # Custom express middlewares
|--models\ # Mongoose models (data layer)
|--routes\ # Routes
|--services\ # Business logic (service layer)
|--utils\ # Utility classes and functions
|--validations\ # Request data validation schemas
|--app.js # Express app
|--server.js # App entry point
To view the list of available APIs and their specifications, run the server and go to http://localhost:3000/v1/docs
in your browser. This documentation page is automatically generated using the swagger definitions written as comments in the route files.
POST /v1/messages
- create a message
GET /v1/messages
- get all messages and associated information about messages
GET /v1/messages/:messageId
- get a message
PATCH /v1/messages/:messageId
- update a message
DELETE /v1/messages/:messageId
- delete a message
- Deployment on minikube for local testing
- CD pipeline
- Setup monitoring and alerting of service using prometheus and grafana
- API security
- Load testing using k6