How to pass arguments to app using pm2?

后端 未结 10 1190
予麋鹿
予麋鹿 2020-12-07 17:29

I am using pm2 to start my app but i am not able to pass argument to it. the command I am using is pm2 start app.js -- dev. Though this works with forever.

10条回答
  •  没有蜡笔的小新
    2020-12-07 17:55

    You need to start pm2 with something like: pm2 start app.js --name "app_name" -- arg1 arg2

    Then in your code, you can get your args with: console.log(process.argv);

    process.argv is a list like this: [ '/usr/local/bin/node', '/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js', 'arg1', 'arg2' ]

提交回复
热议问题