How can I run nodemon from within WebStorm?

Javascriptnode.jsWebstormNodemon

Javascript Problem Overview


I would like to use nodemon from within the WebStorm IDE (version 7). Nodemon watches one or more files in my source folder and restarts the node process (an Express server in this case), when one of the source files changes.

How do I configure WebStorm to use nodemon in a Run Configuration, so that the node process is automatically restarted?

Without nodemon, I use the following configuration in WebStorm, but have to restart the node process whenever I change something in the source file:

  • Node interpreter: /usr/local/bin/node
  • Working directory: /Users/foo/test
  • JavaScript file: server.js

This results in a Run Configuration that runs node server.js in the specified directory.

From command line, I can use the following command to use nodemon to watch for file changes: nodemon server.js in the project directory.

How do I need to change the WebStorm configuration so that it also uses nodemon?

Javascript Solutions


Solution 1 - Javascript

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":

Webstorm with nodemon

@Bela Clark, thanks for confirming.

Solution 2 - Javascript

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 :

enter image description here

Hope it will help you.

Solution 3 - Javascript

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.

Solution 4 - Javascript

I'm on Windows and for me didn't worked with nodemon (no idea why), but someone from Jetbrains suggested to try with supervisor:

  1. I installed supervisor: npm install supervisor -g

  2. 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

  3. 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

edit configurations

node parameters

Solution 5 - Javascript

For those interested for the solution in Windows 10, here is my configuration. It does not show "Terminate Batch" thing and works perfectly.

enter image description here

You press debug ONCE and than you can save change files whatever and the server will restart in debug mode. All brakepoints are working perfectly

Solution 6 - Javascript

For windows users set:

Node Interpreter: Path of the node.exe i.e. c:\program files\node\node.exe

Node parameter: C:\Users\YOURUSER\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js

Solution 7 - Javascript

You can also make it work with nvm and debugging still works.

Tested with Node.js 8.1.0 and Webstorm 2017.2

First make sure you are on the right version (in my case v8.1.0) and install nodemon globally -

nvm use v8.1.0
npm install -g nodemon

Then, open Run/Debug configurations and create a new one with the correct node interpreter.

Node parameters should be:

MAC

/Users/[YOUR_USER]/.nvm/versions/node/v8.1.0/bin/nodemon --inspect=3001

LINUX

/usr/local/nvm/versions/node/v8.1.0/bin/nodemon --inspect=3001

Save and debug respponsibally :)

Node.js nodemon webstorm debug

Solution 8 - Javascript

In case you've installed nodemon like a global library, just set in node parameters:

C:\Users${yourUser}\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js

nodemon in webstorm

Solution 9 - Javascript

Here's the configuration that works for me on Windows 7 + WebStorm 8.0.4. If I put nodemon.cmd as the node interpreter I kept getting "Terminate batch job (Y/N)?".

Nodemon + Webstorm on Windows

Solution 10 - Javascript

This is the only thing that worked for me:

  1. Add a new package.json node run script command:

enter image description here

  1. Create an NPM CONFIG (not a node config)
  2. Select "start-watch" as the command

enter image description here

For me this worked for debugging / breakpoints without issues or additional headache.

Solution 11 - Javascript

  1. Do a npm install nodmemon -g

  2. Only change the Path to Node to the nodemon.cmd, in my case (C:\Users\Rohit Taneja\AppData\Roaming\npm\nodemon.cmd), you'll also get this path after your installion of nodemon finishes.

  3. You're good to go

Solution 12 - Javascript

some of these answers appear to only work for Mac. For Windows, this configuration seems to work (my user name on Windows 7 is denman).

enter image description here

main.js is the starting point file for my Express application.

Solution 13 - Javascript

Just add new script to package.json called nodemon (or choose your own name)

"scripts": {
  ...
  "nodemon": "nodemon ./bin/www"
}

Then go to Run/Debug Configuration and add npm configuration. Set

  • Command to "run"
  • Script to "nodemon" (name you chose in package.json)

example

Solution 14 - Javascript

Per @bernhardw comment, as this was the answer for me -

All is needed is /usr/local/bin/nodemon under node parameters Works for run and debug as it restarts upon changes, but debugging with breakpoint does not work.

Bonus: add -e for more extension e.g /usr/local/bin/nodemon -e js,html,jade

(osx 10.10.5, rubymine 7.1.4)

HTH

Solution 15 - Javascript

npm install -g nodemon

1* goto run->Edit Configurations->Press'+' at left corner and choose Node.js

2* Select Node.js and Press '+' 

3* Name as Nodemon, add path in javaScript file: C:\Users\Your_User_Name\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js

4* Click Apply and Ok

5* Run the Nodemon

[![enter image description here][2]][2][![enter image description here][1]][1]
[1]: http://i.stack.imgur.com/FNVwK.png [2]: http://i.stack.imgur.com/7JKPS.png

Solution 16 - Javascript

Script in package.json: "start": "nodemon --inspect -r babel-register src",

First pic: Run debug and it will start

Second pic: attaching to existing running node Settings enter image description here

Solution 17 - Javascript

Here is a fix for an error I was getting...

If you are using a Windows + NodeJS + nodemon. With an IntelliJ - Run Configuration.

ERROR: starting inspector on failed: address already in use

When I use nodemon version 1.19.1, I get the error. When I use nodemon version 1.18.11, it works!

Good luck...

Solution 18 - Javascript

I have a development in mac and as OdkoPP indicates I made it work

"scripts": {
"build": "tsc",
"dev": "nodemon src/index.ts --exec ts-node"
},

Run/Debug Configurations npm: Run/Debug Configurations npm

Solution 19 - Javascript

This is how I am running

  1. Installed nodemon package

    npm install -g nodemon # OR using yarn: yarn global add nodemon

  2. From Webstorm terminal, run

    nodemon index.js

This is how it will show running in terminal

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnwinklerView Question on Stackoverflow
Solution 1 - JavascriptbernhardwView Answer on Stackoverflow
Solution 2 - JavascriptRPDeshaiesView Answer on Stackoverflow
Solution 3 - JavascriptnwinklerView Answer on Stackoverflow
Solution 4 - JavascriptAlin CiocanView Answer on Stackoverflow
Solution 5 - JavascriptDenko MancheskiView Answer on Stackoverflow
Solution 6 - Javascriptuser3218817View Answer on Stackoverflow
Solution 7 - JavascriptArtipixelView Answer on Stackoverflow
Solution 8 - Javascriptpeterzinho16View Answer on Stackoverflow
Solution 9 - JavascriptRobert JakubowiczView Answer on Stackoverflow
Solution 10 - JavascriptMankind1023View Answer on Stackoverflow
Solution 11 - JavascriptRohit TanejaView Answer on Stackoverflow
Solution 12 - JavascriptAlexander MillsView Answer on Stackoverflow
Solution 13 - JavascriptOdkoPPView Answer on Stackoverflow
Solution 14 - JavascriptHertzel GuinnessView Answer on Stackoverflow
Solution 15 - JavascriptMohammad nabilView Answer on Stackoverflow
Solution 16 - JavascriptViktor BogutskiiView Answer on Stackoverflow
Solution 17 - JavascriptSaganView Answer on Stackoverflow
Solution 18 - JavascriptJuan Camilo Holguin LopezView Answer on Stackoverflow
Solution 19 - JavascriptAmit BaderiaView Answer on Stackoverflow