How to require dotenv/config file on (before) PM2 starts

喜欢而已 提交于 2020-01-25 09:24:10

问题


I run node app like this:

node -r dotenv/config dist/app

I need something similar using PM2:

pm2 start -r dotenv/config dist/app.js --name appname // doesn't work

I receive the next error: error: unknown option -r


回答1:


Using node_args.

pm2 start --node-args="-r dotenv/config" dist/app.js --name appname



回答2:


I have made a Shell script:

// pm2-start.sh

NODE_ENV=production &&
node -r dotenv/config dist/app

Then I ran pm2 start pm2-start.sh --name appname

Tip I have also ran: pm2 startup then copied command that pm2 instructed to run in order to activate the auto startup of all apps that are registered via pm2.

Then I ran pm2 save to save the auto service.

Note: pm2 lists apps distinctly between server account respectively. That means that apps that are listed on user A will not be listed on user B. That's true for the pm2 startup command - that should be done for each account.

Hope it helps.



来源:https://stackoverflow.com/questions/56832158/how-to-require-dotenv-config-file-on-before-pm2-starts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!