pm2.config.js:
var pm2Config = {
apps : [{
exec_mode: "fork_mode",
script: "app.js",
name: "NDFS_REVIEW_APP--00",
node_args: [],
env: {
NODE_ENV: "development",
PORT: 3000
},
env_production : {
NODE_ENV: "production",
PORT: 3000
},
error_file: "/NDFS_REVIEW_APP--00.err.log",
out_file: "/NDFS_REVIEW_APP--00.out.log"
},
{
exec_mode: "fork_mode",
script: "app.js",
name: "NDFS_REVIEW_APP--01",
node_args: [],
env: {
NODE_ENV: "development",
PORT: 3001
},
env_production : {
NODE_ENV: "production",
PORT: 3001
},
error_file: "/NDFS_REVIEW_APP--01.err.log",
out_file: "/NDFS_REVIEW_APP--01.out.log"
}
],
};
module.exports = pm2Config;
app.js
server.httpServer.listen(process.env.APP_PORT,function(){
logger.info("Application Server started at port :" + process.env.APP_PORT);
console.log('The HTTP server is running on port '+process.env.APP_PORT);
console.log('pid is ' + process.pid);
});
使用以下命令启动服务器:
pm2 start pm2.config.js
已创建两个node.exe实例,但是服务器仅在3001上作为.env文件中的process.env.APP_PORT = 3001运行。如何从pm2配置文件中获取端口号并在不同端口中运行同一应用程序?