A demo project to demonstrate how to convert a Node.js monolithic application into a microservices architecture. This project is structured to help beginners understand the concepts of microservices, service isolation, and API gateways.
nodejs-monolith-to-microservices/
├── api-gateway/
│ ├── src/
│ └── package.json
├── services/
│ ├── user-service/
│ │ ├── src/
│ │ └── package.json
│ ├── order-service/
│ │ ├── src/
│ │ └── package.json
│ └── product-service/
│ ├── src/
│ └── package.json
├── shared/
│ ├── db/
│ └── utils/
├── docker-compose.yml
└── README.md
- Independent services: Each microservice (User, Order, Product) runs independently.
- API Gateway: Routes client requests to the appropriate service.
- Database isolation: Each service can have its own database.
- Scalable architecture: Microservices allow independent scaling and development.
- CORS & JSON parsing configured in each service.
- Node.js
- Express.js
- TypeScript
- MongoDB / PostgreSQL (per service)
- Docker & Docker Compose
- CORS
git clone https://github.com/yourusername/nodejs-monolith-to-microservices.git
cd nodejs-monolith-to-microservices
npm install
For example, to run the user service:
cd services/user-service
npm install
npm run dev
Then the API will be available at: http://localhost:3001
cd api-gateway
npm install
npm run dev
Requests to http://localhost:3000/api/users
will be forwarded to the user service.
GET /health
Response:
{
"status": "user service is up and running"
}
POST /api/users/register
Body:
{
"name": "John Doe",
"email": "john@example.com",
"password": "password123"
}
- Convert user module to microservice
- Convert order module to microservice
- Convert product module to microservice
- Add message queue (RabbitMQ / Kafka) for async communication
- Add service discovery (optional)
- Dockerize all services
Surya Singh
MIT