node.jsubuntu-16.04systemdpm2ubuntu-server

pm2 with systemd and passing node argument


I want to start node with pm2 and environment variables like --nouse-idle-notification or --max-old-space-size=2048.

However, whatever I do, it is not passing the node variables. I start my app with pm2 and a configuration file. The configuration file looks like:

{
  "apps" : [{
    "env": {
      "NODE_PATH": "/usr/bin/node",
      "interpreter_args": "--max-old-space-size=2048 --nouse-idle-notification"
    },
    "env_development": {
      "NODE_ENV": "development"
    },
    "env_production" : {
       "NODE_ENV": "production",
       "APP_TYPE": "web"
    },
    "exec_mode"   : "fork",
    "name"        : "MyApp",
    "script"      : "/opt/myapp/app.js",
    "watch"       : false,
    "out_file"    : "/var/log/app.log",
    "error_file"  : "/var/log/app.log",
    "combine_logs": true,
    "node_args": "--max-old-space-size=2048 --nouse-idle-notification",
    "args": "--max-old-space-size=2048 --nouse-idle-notification"
  }]
}

(as you can see I try to pass in the node variables in multiple ways)

I then start the app with:

pm2 restart pathtojsonfile --env production

Everything is starting up properly and I see variables like "MY_APP" in my code. However, now when I look at the process with "top" I only see:

node /opt/myapp/app.js

When I start the app with forever or manually I can see the process like:

node --max-old-space-size=2048 --nouse-idle-notification /opt/myapp/app.js

Is pm2 just not showing those node arguments or are they really not passed in? (The pm2 started process uses less memory)


Solution

  • By using "node_args": "--max-old-space-size=2048 --nouse-idle-notification" you did the right thing and these arguments are taken into account.

    PM2 renames the process and drop the specified node argument in the process title.