【发布时间】:2020-04-19 17:19:51
【问题描述】:
当使用 node 启动我的应用程序时,我通常会运行:
node -r dotenv/config ./build/index.js
在 fork 模式下使用 PM2 时,我可以像这样启动应用程序:
pm2 start --node-args="-r dotenv/config" build/index.js --name API
如果我尝试在集群模式下运行应用程序,它似乎会忽略 node-args 并且无法加载环境变量。
pm2 start --node-args="-r dotenv/config" build/index.js -i max --name API
在不将其显式添加到应用程序代码中的情况下,解决此问题的正确解决方法是什么?我一开始就应该这样做吗?
更新:如果您希望在集群模式下运行应用程序,pm2 ecosystem 似乎是注入命令行参数的正确方法。使用node_args: '-r dotenv/config' 我能够达到预期的结果。谢谢!
附:确保将环境设置为生产环境,否则在启动应用程序时可能会遇到意外问题。
【问题讨论】:
标签: node.js reactjs pm2 dotenv