Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug application which is run using pm2

Tags:

pm2

Application is run by

pm2 start app.js 

or

pm2 start config.json 

I want to debug my application locally using node_inspector. I added debug argument

pm2 start --node-args="--debug=7000" app.js 

It works fine but if I provide config.json instead of script app.js I don't know how to pass arguments about debug. Next piece of config doesn't work

{   "apps": [     {       "name": "myName",       "script": "app.js",       "args": "['--debug=7000']"       ............       }     ] } 

So How to debug application which is run by pm2 and using config?

like image 714
Nawa Avatar asked Apr 27 '15 15:04

Nawa


People also ask

How do I check pm2 logs?

Application Logs Once an application is started with PM2 you can consult and manage logs easily. Log files are located in the folder $HOME/. pm2/logs .

How do I monitor pm2 process?

Monitoring Nodejs Application Using PM2 TerminalTo view logs of an app, first select it (use up/down arrows) from the process list. The terminal-based monitoring only works well for applications running on a single server. To monitor and diagnose cross-server applications, use the PM2 web-based dashboard.

Where are pm2 logs stored?

By default, all logs are saved into $HOME/. pm2/logs .


1 Answers

You're almost there, use node_args instead of args:

  • args are your script arguments
  • node_args are arguments that are passed to node executable

    {   "name": "myName",   "script": "app.js",   "node_args": ["--debug=7000"] } 

PM2 json schema.

If someone still has problems with the debug setting after this, in some case you have to disable the cluster mode for the debug setting to be effective.

Also note that you don't need the brackets in the node_args value if you pass all the args as a single string.

like image 138
soyuka Avatar answered Oct 07 '22 22:10

soyuka