Run node.js application in debug with supervisor

12.1k Views Asked by At

I am using supervisor to auto-reload my node.js, e.g.

supervisor -w . app.js

However I can't work out how to get supervisor to run the node.js process in debug, e.g. the equivalent to

node --debug app.coffee

Anyone got any ideas?

5

There are 5 best solutions below

1
On BEST ANSWER

This solution will work for *nix:

Go to /usr/local/bin or any other directory in your $PATH

$ cd /usr/local/bin

Create an executable script (say, node-debug) with the following contents

#!/bin/bash
node --debug $@

To make it executable:

$ sudo chmod 777 /usr/local/bin/node-debug

Now you can run supervisor like this:

$ supervisor -x node-debug script.js

P.S.: To round it up:

su
echo '#!/bin/bash
node --debug $@' > /usr/local/bin/node-debug
chmod 777 /usr/local/bin/node-debug
1
On

This also works (and you don't need a separate bash script):

supervisor -- --debug app.js
supervisor -- --debug=7070 app.js
2
On

Use the -x flag as documented on the node-supervisor github page

supervisor -w . -x 'node --debug' app.js

but that won't work with coffeescript so you have to use

supervisor -w . -x 'coffee --debug' app.js

0
On

node-dev

node-dev on Github

"All arguments are passed on to the child-process. node-dev --debug server.js will debug your application, not the supervisor itself."

Create a "test.js" node.js script in $HOME/nodetest

First terminal (run node in debug mode, debug will listen on the port 5858, node-dev will reload changed files):

    cd $HOME/nodetest
    npm install node-dev
    node_modules/.bin/node-dev --debug test.js

Second terminal (start web inspector for a WebKit based browser, inspector connects to the port 5858 of the debugger and listens on the port 8080):

    cd $HOME/nodetest
    npm install node-inspector
    node_modules/.bin/node-inspector

Open this URL in a WebKit based browser (Chrome, Safari, etc.):

    http://0.0.0.0:8080/debug?port=5858

Click on "Scripts" and set breakpoints in your code.

0
On

From the CoffeeScript site :

--nodejs The node executable has some useful options you can set, such as --debug, --debug-brk and --max-stack-size. Use this flag to forward options directly to Node.js.

I tried this and it worked:

supervisor -- --nodejs --debug app.coffee

You can add other arguments like this:

supervisor -w . -n error -- --nodejs --debug app.coffee