94

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?

nwinkler
  • 52,665
  • 21
  • 154
  • 168
  • This question seems to be along the same lines: http://stackoverflow.com/questions/11175041/script-fails-in-webstorm-but-not-from-terminal?rq=1 – nwinkler Oct 04 '13 at 13:42
  • See my answer https://stackoverflow.com/a/52463378/7350853 is using the most updated version of the Webstorm so far. – iwaduarte Sep 23 '18 at 06:11

19 Answers19

159

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.


You may NOT have nodemon exists from which nodemon command, then you should have it in your package.json ie nodemon be installed at :project_dir/node_modules/.bin/nodemon

Then from Webstorm 's run/debug config, set Node parameters to be

:path_to_project_dir/node_modules/.bin/nodemon

You should save the debug/run config to file so your teammates can also easily debug/run your nodejs app like you

enter image description here

This will save the config into some .xml file, sample as below

<component name="ProjectRunConfigurationManager">
  <configuration default="false" name="index.js" type="NodeJSConfigurationType" path-to-node="$USER_HOME$/.nvm/versions/node/v19.4.0/bin/node" nameIsGenerated="true" node-parameters="../node_modules/.bin/nodemon" path-to-js-file="index.js" working-dir="$PROJECT_DIR$/nodejs27/node27_sequelize_apiapp/src">
    <method v="2" />
  </configuration>
</component>
Nam G VU
  • 33,193
  • 69
  • 233
  • 372
bernhardw
  • 3,239
  • 2
  • 20
  • 16
  • Just gave this a try - it works perfectly fine now. Thanks for providing an updated answer! – nwinkler Mar 24 '14 at 07:07
  • 9
    @bernhardw, webstorm doesn't stop on breakpoints when starting debugger with these configurations. Any idea why? – Nik Sumeiko Jan 20 '15 at 18:13
  • 4
    Managed to get nodemon and breakpoints working by following these instructions: https://vcfvct.wordpress.com/2015/02/13/debug-nodejs-with-nodemon-and-intellij/ Note that I used --debug-brk instead of --debug – n00b Sep 07 '15 at 04:48
  • 1
    To make debugging work I had to use Live Edit plugging for IntelliJ instead of nodemon. – engin Feb 01 '16 at 06:16
  • 1
    Good answer ! Thank you – Julien Feb 22 '16 at 01:02
  • But, debugging is not working i.e program is not stopping at breakpoints. ?? – Akshay Pratap Singh Sep 08 '16 at 11:21
  • to stop at breakpoints you have to put the parameter --inspect-brk in 'node parameters: ' and run in debugging mode. – iwaduarte Sep 22 '18 at 15:37
  • Following on from iwaduarte's breakpoint fix, `--inspect-brk` has to go into Application Parameters to work, not Node Parameters (for me anyway - WebStorm 2019.1.4) – rorymorris89 Aug 22 '19 at 21:28
  • reminder: you have to physically click on the run window in order for it to update after you implement this solution – Embedded_Mugs Mar 03 '22 at 21:39
  • Didn't work for me at all on MacOS 13.1, node 18, nodemon 2.0.20. nodemon doesn't start with this config (which seems logical, as it is a binary in my case and works as a standalone binary and not as a node parameter - though it worked for many people somehow...). This answer helped me to start nodemon: https://stackoverflow.com/a/26345577/11575732 – Denis P Dec 29 '22 at 18:33
40

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.

steampowered
  • 11,809
  • 12
  • 78
  • 98
RPDeshaies
  • 1,826
  • 1
  • 24
  • 29
  • I thought this was the most straight forward answer. – Paul Wade May 19 '14 at 15:50
  • 6
    Hi, Tried this and when I change a file it asks me (in the Web Storm console) "Terminate batch job (Y/N)?". I also see that the command being executed is: "C:\Program Files (x86)\JetBrains\WebStorm 8.0.4\bin\runnerw.exe" C:\Users\xyz\AppData\Roaming\npm\nodemon.cmd --debug-brk=27344 --nolazy -q app.js. Am I missing anything? – Tomer Cagan Aug 26 '14 at 13:06
  • 1
    for the "terminate batch job" problem just add " < nul" (leave out quotations) to the "Application parameters" input. (answer found here: http://superuser.com/a/498798) – Tobias Weichart Mar 16 '16 at 15:12
  • Why is this upvoted ? It won't work, when nodemon restarts it doesn't add the " – KVM Mar 29 '16 at 00:37
  • 1
    the location in windows is C:\Users\\AppData\Roaming\npm\nodemon.cmd – Frido Emans Dec 26 '20 at 21:16
20

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.

nwinkler
  • 52,665
  • 21
  • 154
  • 168
17

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

e-shfiyut
  • 3,538
  • 2
  • 30
  • 31
Alin Ciocan
  • 3,082
  • 4
  • 34
  • 47
  • 1
    To stop on breakpoint you should add this: `--debug-brk` and complete string is `C:\Users\\AppData\Roaming\npm\node_modules\supervisor\lib\cli-wrapper.js no-restart-on error --debug-brk` Check from jetbrains http://www.jetbrains.com/phpstorm/webhelp/run-debug-configuration-node-js.html address – uzay95 Oct 07 '14 at 08:05
  • 1
    Couldn't get nodemon working on Windows 8 with Webstorm 9, this worked like a charm tho – Simon Trewhella Nov 27 '14 at 06:27
  • 1
    Works for me (Webstorm 11 on Windows) but the breakpoints don't work. I tried adding `--debug-brk` but no luck. – electrotype Nov 10 '15 at 17:18
  • [Start nodemon with `--inspect` flag and then attach a debugger to it](https://www.jetbrains.com/help/idea/running-and-debugging-node-js.html#nodemon). – brgs Sep 18 '18 at 16:28
17

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

Denko Mancheski
  • 2,709
  • 2
  • 18
  • 26
  • this is working answer for debug. I set only node parameters. node parameters as text (change username): c:\users\username\AppData\Roaming\npm\node_modules\nodemon\bin\nodemon.js --debug=3001 – Alexey Obukhov Jun 14 '17 at 15:03
  • This didn't work for me. Adding the --debug=3001 parameter crashed nodemon – JCF Mar 22 '19 at 15:00
  • Thanks.The basic run is working and also the debug without any problems!This should be TOP answer! – Georgi Peev Aug 27 '19 at 18:41
9

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

user3218817
  • 91
  • 1
  • 1
  • This worked for me! Debugging and break points work perfectly. Node version 10.15.1 nodemon version 1.18.10 Webstorm 2018.3.5 – JCF Mar 22 '19 at 14:58
5

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

Artipixel
  • 1,246
  • 14
  • 17
5

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

peterzinho16
  • 919
  • 1
  • 15
  • 18
5

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.

Mankind1023
  • 7,198
  • 16
  • 56
  • 86
  • Seems if you do this, "break on exception" does not break on exceptions:( – Mr_E Jun 23 '21 at 14:29
  • It worked like a charm for me on MacOS 13.1, node 18. Stops at breakpoints very well. On the contrary, using Node configuration (as in most top answers) doesn't start. – Denis P Dec 29 '22 at 18:28
4

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

Robert Jakubowicz
  • 338
  • 1
  • 4
  • 11
1
  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

Rohit Taneja
  • 179
  • 1
  • 6
1

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.

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
1

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

OdkoPP
  • 442
  • 6
  • 14
1

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

h3t1
  • 1,126
  • 2
  • 18
  • 29
0

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

Hertzel Guinness
  • 5,912
  • 3
  • 38
  • 43
0

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 hereenter image description here

Mohammad nabil
  • 1,010
  • 2
  • 12
  • 23
0

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

Viktor Bogutskii
  • 870
  • 1
  • 14
  • 22
0

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

Sagan
  • 2,033
  • 2
  • 14
  • 12
0

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

Amit Baderia
  • 4,454
  • 3
  • 27
  • 19