问题
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