简体   繁体   中英

Passing and Reading Parameters in PM2

I want to pass command line arguments to my script. In forever I used to pass arguments like

forever start example.js 8080

I am unable to figure out how to do it in PM2. I tried

pm2 start KratosReq.js  -- -p 8080

but while reading from process.argv, the array contains

[ 'node', '/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js' ]

Pm2 wrap your init script and fork node processes(cluster mode) , i think that is why you have that output , looking for declare enviroment variables in pm2 , you can use a json file to start up your server , or you can just start passing --node-args argument(checking pm2 help , there is that argument) , something like :

pm2 start KratosReq.js  --node-args="-p=8080"

Hope this could help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM