How to add production mode to sailsjs app when started using PM2
Asked Answered
S

7

5

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?

Schism answered 14/4, 2014 at 8:42 Comment(0)
I
5

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

[{
  "name"      : "Sails",
  "script"    : "./app.js",
  "args"      : "['--prod']"
}]
Infatuation answered 14/4, 2014 at 10:18 Comment(1)
Typical.. Already tested this earlier, got a weird error, thought that the args wasn't properly passed, so I removed it. Looks like that wasn't the problem at all. Works like a charm, thank you!Schism
W
2

first delete: pm2 delete app

again:

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

Weddle answered 26/10, 2015 at 19:22 Comment(0)
M
1

You can also use something like this:

NODE_ENV=production pm2 start app.js
Muggy answered 26/5, 2014 at 0:57 Comment(0)
G
1

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

pm2 start app.js -x --prod
Gayden answered 2/7, 2015 at 5:53 Comment(0)
S
0

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
Slosh answered 24/4, 2017 at 7:6 Comment(0)
U
0

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.

Unfathomable answered 8/11, 2017 at 11:9 Comment(0)
N
0

1.

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

2.

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

Narbada answered 3/5, 2019 at 9:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.