Search This Blog

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.

  1. Install PM2 globally:


    npm install pm2 -g
  2. Create 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', }, }, ], };
  3. Start all services:


    pm2 start ecosystem.config.js
  4. Monitor services:

    pm2 list
Cheers,

Kapil 

No comments:

Post a Comment

Thanks for your comment, will revert as soon as we read it.

Popular Posts