Microservice architecture with node js and MongoDB
Project Setup with Docker
Install Docker & Docker Compose
1 - Clone project from repository:
git clone https://github.com/muhammadbinnaeem/xendit.git
2 - Enter the xendit folder and rename env-example to .env.
cd xendit
cp env-example .env
3 - Run your containers:
docker-compose up -d
if the above command failed with this:
ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
Run with sudo
4 - Open postman or any other tool for testing API and visit localhost:8080.
API Routes
1 - Login with credentials:
Request URL: http://localhost:8080/api/v1/auth/login
Request Method: POST
Request body: {
"email":"mbinnaeem20@gmail.com",
"password":"Abc123@@"
}
2 - Add comment:
Request URL: http://localhost:8080/api/v1/orgs/xendit/comments
Request Method: POST
Request header: {
"Authorization":"Bearer ${token-return-in-login-request}"
}
Request body: {
"comment":"This is a test comment"
}
3 - Get comments:
Request URL: http://localhost:8080/api/v1/orgs/xendit/comments
Request Method: GET
Request header: {
"Authorization":"Bearer ${token-return-in-login-request}"
}
4 - Delete comments:
Request URL: http://localhost:8080/api/v1/orgs/xendit/comments
Request Method: DELETE
Request header: {
"Authorization":"Bearer ${token-return-in-login-request}"
}
5 - Get members:
Request URL: http://localhost:8080/api/v1/orgs/xendit/members
Request Method: GET
Request header: {
"Authorization":"Bearer ${token-return-in-login-request}"
}
NOTE: Xendit.postman_collection.json is also uploaded at root directory.
Project summary
On docker-compose up -d, four docker containers will be created:
mongo: For database
ms-auth: For login and authenticating other services. It will work as API Gateway.
ms-comments: For comments module.
ms-members: For members module.
Packages used
Jest and supertest for testing.
winston, winston-daily-rotate-file and morgan for logging.
jsonwebtoken and passport for authentication.
request-promise-native for proxy request.
mongoose-seed for seeding.
mongoose-delete for soft delete.