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

后端 未结 7 1966
心在旅途
心在旅途 2021-01-13 06:57

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,

相关标签:
7条回答
  • 2021-01-13 07:22

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

    pm2 start app.js -x --prod
    
    0 讨论(0)
  • 2021-01-13 07:25

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

    [{
      "name"      : "Sails",
      "script"    : "./app.js",
      "args"      : "['--prod']"
    }]
    
    0 讨论(0)
  • 2021-01-13 07:31

    first delete: pm2 delete app

    again:

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

    0 讨论(0)
  • 2021-01-13 07:35

    You can also use something like this:

    NODE_ENV=production pm2 start app.js
    
    0 讨论(0)
  • 2021-01-13 07:42

    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.

    0 讨论(0)
  • 2021-01-13 07:47

    1.

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

    2.

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

    0 讨论(0)
提交回复
热议问题