Technology & Tips
This blog is dedicated to share my experience during my development as a purpose of notes and explorer various web / enterprise technologies like JAVA , JEE , Spring ,hybris, Portal , Jquery , RAI , JMS, Weblogic , SSL , Security, CS, MAC< Linux, Windows, Search, IOT, Arduino, Machine Learning, Tips, Angular, Node JS, React, Mac, Windows, Stack, Exception, Error etc. with examples.
Search This Blog
Tuesday, May 12, 2026
How to Add an MCP Server to Claude in VS Code
Wednesday, January 29, 2025
How to use PM2 to Manage Multiple Node Services in production
If you want to manage and monitor the services, you can use PM2, a process manager for Node.js. This is particularly useful in production environments.
Install PM2 globally:
npm install pm2 -gCreate an ecosystem file (e.g.,
ecosystem.config.js) to define all services:module.exports = { apps: [ { name: 'microservice1', script: './microservice1/server.js', watch: true, env: { NODE_ENV: 'production', }, }, { name: 'microservice2', script: './microservice2/server.js', watch: true, env: { NODE_ENV: 'production', }, }, { name: 'microservice3', script: './microservice3/server.js', watch: true, env: { NODE_ENV: 'production', }, }, ], };Start all services:
pm2 start ecosystem.config.jsMonitor services:
pm2 list
How can package all microservices using docker
If each of your microservices is containerized using Docker, you can use Docker Compose to define and run all of your services in one go. This is one of the most common ways to manage multiple microservices.
Steps:
Create Dockerfiles for each microservice (if you haven't already): Each microservice should have its own
Dockerfileto build the image. For example:dockerfile:# Dockerfile for microservice 1 FROM node:14 WORKDIR /app COPY . . RUN npm install CMD ["npm", "start"Create a
docker-compose.ymlfile at the root of your project: This will define all your microservices and how they interact.version: "3" services: microservice1: build: context: ./microservice1 ports: - "3001:3001" environment: - NODE_ENV=production microservice2: build: context: ./microservice2 ports: - "3002:3002" environment: - NODE_ENV=production microservice3: build: context: ./microservice3 ports: - "3003:3003" environment: - NODE_ENV=productionRun all services with Docker Compose:
- In the root directory where your
docker-compose.ymlfile is, simply run:
docker-compose up --buildThis command will build the Docker images (if necessary) and start all the services.
- In the root directory where your
Stopping the services:
docker-compose down
Popular Posts
-
Using npm scripts to start all services If your microservices are not containerized, you can set up an npm script to run all services wi...
-
We can install apk into emulator with following steps : Paste the .apk file to platform-tools in the android-sdk Linux/MAC fo...
-
I was getting following problem after copying JAD plugin jar into eclipse plugin folder : java.io.IOException: Cannot run program ...
-
Today we were facing some UI issues in different versions of browser. To troubleshoot the problem I found an exe which has collection of IE...