How to add production mode to sailsjs app when started using PM2

青春壹個敷衍的年華 提交于 2019-12-01 04:03:23

问题


To start sailsjs in production mode you append --prod.

Run: node app.js --prod

I'm using PM2 and a simple json file for settings, which contains name of process and scriptname, to kick off the node process.

How would I pass the production argument using PM2?


回答1:


Read PM2 JSON app declaration. E.g. (not tested)

[{
  "name"      : "Sails",
  "script"    : "./app.js",
  "args"      : "['--prod']"
}]



回答2:


first delete: pm2 delete app

again:

pm2 start app.js -x -- --prod




回答3:


You can also use something like this:

NODE_ENV=production pm2 start app.js



回答4:


According to the official document you can do it like this:

pm2 start app.js -x --prod



回答5:


For pm2 if you have created ecosystem.config.js which you should create in the first process according to this official document. By default it will consider development mode and if you want to change then first delete the previous instance with following command.

pm2 delete <ID|APP_NAME|SCRIPT|ALL|JSON>

Then you start the instance with following command.

pm2 start ecosystem.config.js --env production

And to check the process tail the logs of pm2 with following command.

pm2 logs



回答6:


Here is my configuration file for PM2 and I have running multiple service under PM2 as one of them below, apps.json

{
  "apps": [
    {
      "name"       : "TEST_APP",
      "script"     : "./app.js",
      "cwd"        : "/Users/username/app",
      "merge_logs" : true,
      "out_file"   : "logs/pm2-out.log",
      "error_file" : "logs/pm2-err.log",
      "instances"  : 3,
      "exec_mode"  : "cluster",
      "env"        : {
                        "NODE_ENV": "dev",
                        "PORT": "9999"
                     }, 
      "env_production": {
                        "NODE_ENV": "production",
                        "PORT": 9998
                     }  
    }
  ]
}
Then simply run the following command to run your service,
$ pm2 start apps.json --env production

You can include other parameters as mentioned in the PM2 docs here. Hope this helps.




回答7:


1.

NODE_ENV=production pm2 start app.js -- --prod

2.

NODE_ENV=production pm2 start app.js --name "myapp" -i max -- --prod



来源:https://stackoverflow.com/questions/23055633/how-to-add-production-mode-to-sailsjs-app-when-started-using-pm2

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