How can I run nodemon from within WebStorm?
It looks like the workaround with --exec
isn't necessary anymore, at least when using the newest version of nodemon and Webstorm 7 or 8.
All you have to do is specify your path to nodemon by obtaining its path with running which nodemon
in your console (e.g. /usr/local/bin/nodemon
) under "Node parameters":
@Bela Clark, thanks for confirming.
To install nodemon, use the following (if required, use sudo to run the installation with root privileges:
npm install -g nodemon
This will install nodemon globally on your machine.
Then, in your WebStorm Run Configuration, add the following, leaving everything else unchanged:
- Node parameters:
/usr/local/bin/nodemon --exec /usr/local/bin/node
This will instruct the node interpreter to execute the nodemon
script using the following command line: node /usr/local/bin/nodemon --exec /usr/local/bin/node server.js
.
The --exec
part is important, as the execution will fail with the following error:
/usr/local/bin/node /usr/local/bin/nodemon server.js
4 Oct 13:56:50 - [nodemon] v0.7.10
4 Oct 13:56:50 - [nodemon] to restart at any time, enter `rs`
4 Oct 13:56:50 - [nodemon] watching: /Users/foo/test
execvp(): No such file or directory
4 Oct 13:56:50 - [nodemon] starting `node server.js`
4 Oct 13:56:50 - [nodemon] exception in nodemon killing node
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
The error seems to be caused by WebStorm not seeing the node
executable on its path.
The fix for this is to specify the location to the node
executable using the --exec /usr/local/bin/node
parameter.
Using these settings, nodemon works fine when run from a WebStorm Run Configuration.
The same trick might have to be used with some of the tools similar to nodemon, e.g. node-supervisor.
This is the Windows solution
You can just use the nodemon.cmd instead of node directly like :
Node interpreter : C:\MyPath\To\nodemon.cmd
Node parameters : /*Empty for me*/
Node WorkingDirectoy : C:\Users\MyUserName\Desktop\DirectoryContainingMyIndex.js
JavaScriptFile : app\index.js /*or just index.js depending on your config*/
and then :
Hope it will help you.
I'm on Windows and for me didn't worked with nodemon (no idea why), but someone from Jetbrains suggested to try with supervisor:
I installed supervisor:
npm install supervisor -g
Then find where is
supervisor
installed, for me was in:C:\Users\AlinC\AppData\Roaming\npm\node_modules\supervisor\lib\cli-wrapper.js –no-restart-on error
I went back to Intellij: edit configurations -> node parameters -> and added: C:\Users\AlinC\AppData\Roaming\npm\node_modules\supervisor\lib\cli-wrapper.js –no-restart-on error