How to specify a port number for pm2

前端 未结 3 1075
执笔经年
执笔经年 2021-02-01 16:37

I\'m trying to use pm2 to manage a node.js cluster

pm2 start . -i 3

I\'m currently running the app on heroku and using a Procfile with the abov

3条回答
  •  遥遥无期
    2021-02-01 17:04

    You can use environment variable. For example:

    1) NODE_PORT=3002 pm2 start -I 0 app.js

    2) Read value in app:

    console.log(process.env.NODE_PORT);

    Or, if you are build express app:

    1) PORT=3002 pm2 start -I 0 ./bin/www

    2) Express load PORT automatically at start application.

提交回复
热议问题