Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use configuration files to manage multiple Node.js processes

Shulou Source: shulou.com Published: 2022-06-02 09:41:09 09月27日 Update

This article mainly introduces "how to use configuration files to manage multiple Node.js processes". In daily operation, I believe many people have doubts about how to use configuration files to manage multiple Node.js processes. Xiaobian consulted all kinds of information and sorted out simple and easy to use operation methods. I hope to answer your doubts about "how to use configuration files to manage multiple Node.js processes"! Next, please follow the small series to learn together!

I. Brief description of the problem

When multiple Node.js processes need to be managed together, and each requires different parameters, it is best to create a configuration file to manage them.

II. Solutions

1. Generate a basic version configuration file

pm2 init simple: can generate the basic version of the configuration file: ecosystem.config.js

// ecosystem.config.jsmodule.exports = { apps: [{ name: "app1", script: "./ app.js" }]}

2. Generate complex versions of configuration files

pm2 init is equivalent to pm2 ecosystem, which can generate configuration file with deploy attribute: ecosystem.config.js

module.exports = { apps: [{ script: 'index.js', watch: '. ' }, { script: './ service-worker/', watch: ['./ service-worker'] }], deploy: { production: { user: 'SSH_USERNAME', host: 'SSH_HOSTMACHINE', ref: 'origin/master', repo: 'GIT_REPOSITORY', path: 'DESTINATION_PATH', 'pre-deploy-local': '', 'post-deploy': 'npm install && pm2 reload ecosystem.config.js --env production', 'pre-setup': '' } }};

This version is configured for use with remote configuration servers, see examples here!

https://learn-anything.cn/pm2-nodejs-deploy

3. Use configuration files

Start, Stop, Restart, Reload, Delete all items in configuration file

pm2 start ecosystem.config.jspm2 stop ecosystem.config.jspm2 restart ecosystem.config.jspm2 reload ecosystem.config.jspm2 delete ecosystem.config.js

Launch specified application

pm2 start ecosystem.config.js --only api-apppm2 start ecosystem.config.js --only "api-app,worker-app" This is the end of learning about "how to use configuration files to manage multiple Node.js processes", hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Tags: Configuration file management multiple process version learning generation foundation scheme more problem help complex practical next parameters at the same time instances properties Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei vpn NVidia MariaDB Xiaomi