17

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?

Martijn Pieters
  • 889,049
  • 245
  • 3,507
  • 2,997
James Hollingworth
  • 13,192
  • 12
  • 37
  • 56

5 Answers5

26

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

supervisor -- --debug app.js
supervisor -- --debug=7070 app.js
Jesper
  • 572
  • 7
  • 16
  • 1
    this one should be the accepted answer. Thank you for sharing. – Daniele Vrut Jun 22 '14 at 11:56
  • Yes this works so simply, and also with the "advanced" inspector too, e.g. for running Express: `DEBUG=myapp:* supervisor -- --inspect bin/www`. I got event-errors trying to use the -x parameter, but this alternative parameter format works. – scipilot Jun 03 '17 at 08:02
9

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
TEHEK
  • 972
  • 8
  • 8
  • This way I get `debugger listening on port 5858 Failed to open socket on port 5858, waiting 1000 ms before retrying` while manual `node --debug` works fine. – Redsandro Jul 03 '14 at 10:51
3

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

3

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.

Junaid Qadir Shekhanzai
  • 1,287
  • 1
  • 18
  • 34
devhd
  • 31
  • 2
0

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

Raynos
  • 156,883
  • 55
  • 337
  • 385
  • 3
    tried that but it goes into an infinite loop with DEBUG: Starting child process with 'coffee --debug app.coffee' DEBUG: execvp(): No such file or directory – James Hollingworth Jun 24 '11 at 14:28
  • @JamesHollingworth I think it was too much to expect `coffee --debug` to just work :P – Raynos Jun 24 '11 at 15:06