How can I pass arguments to the executable in nodemon (or node-supervisor)?
Asked Answered
S

3

22

node can be run with a debug parameter like this

$ node --debug src/file.js

I can also pass that parameter through the coffee-script binary like this

$ coffee --nodejs --debug src/file.coffee

Which works. But things get more difficult when I involve supervisor. Running coffee scripts is no problem:

$ supervisor -w src src/file.coffee

But I want to debug the coffee scripts that I'm running with supervisor. How can I send arguments such as --debug through supervisor? I tried setting the executable to a string with the arguments like this:

$ supervisor -w src -x "coffee --nodejs --debug" src/server.coffee

Which produced an infinitely repeating error message saying

DEBUG: Starting child process with 'coffee --nodejs --debug src/server.coffee'
DEBUG: execvp(): No such file or directory

Which is odd, because running coffee --nodejs --debug src/server.coffee in the terminal works.

So how can I send arguments through supervisor?


Edit: I want to expand my question with mentioning that I've now tried using nodemon as well. It seems nodemon is considered preferable to node-supervisor, so I'll accept any answer that explains how to pass --debug to the node process when launching coffee scripts through nodemon


Edit: Here's the output from nodemon. Clearly the arguments are not passed in the same order :-(

$ nodemon -w src -x coffee --nodejs --debug src/server.coffee
15 Jan 03:41:56 - [nodemon] v0.6.5
15 Jan 03:41:56 - [nodemon] watching: /foo/bar/server/src
15 Jan 03:41:56 - [nodemon] running --debug
15 Jan 03:41:56 - [nodemon] starting `coffee --debug --nodejs src/server.coffee`

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^

Error: unrecognized option: --debug
Sunburst answered 14/1, 2012 at 23:31 Comment(1)
New to node here. Any details on why nodemon is preferable to supervisor? One thing I've noticed is that after a crash, there's no frantic attempt at restarting.Flofloat
T
15

actually, it turned out to be a bug :)

The short way:

nodemon --debug -w src src/server.coffee

Or (where --nodejs and --debug are included as the exec)

nodemon -x "coffee --nodejs --debug" -w src src/server.coffee

Or (looks nicer than above)

nodemon -x coffee --nodejs --debug -w src src/server.coffee

(all on nodemon 0.6.6)

Tehee answered 16/1, 2012 at 20:9 Comment(1)
Just for the record, this did not work at the time when I asked this question. It was fixed later. None the less, it is correct nowSunburst
R
11

You can use -- with supervisor. Not sure if this would work with the -x syntax though:

supervisor -w src -- coffee.js --nodejs --debug src/server.coffee

Ramulose answered 5/12, 2012 at 12:55 Comment(1)
This sort of thing can in fact work with the --exec/-x syntax. For example, the following worked for me: supervisor --watch src/index.js --exec serve -- -n -s build, where serve's arguments come after the --.Carew
H
1

From a quick review of supervisor, it look like it passes all arguments as arguments to the script itself, so you'll want to use nodemon.

Nodemon picks out it's own arguments, but otherwise they are passed to node. In the current version, arguments after the js/coffee file are preserved, and arguments before the JS file have their order inverted, so try this.

nodemon -w src -x coffee --debug --nodejs src/server.coffee

Of course, it looks like you noticed that too :P https://github.com/remy/nodemon/issues/54

So yeah, the ordering issue is a bug that hopefully will get fixed.

Haleakala answered 15/1, 2012 at 2:35 Comment(3)
They aren't passed in the same order, see my latest question update. ThanksSunburst
Updated. Are you going to make a patch? It should be pretty easy, so if aren't let me know and I'll do it.Haleakala
I would add that supervisor seems to have issues under windows passing arguments correctlyClaar

© 2022 - 2024 — McMap. All rights reserved.