How can I run nodemon from within WebStorm? - javascript

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?

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

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.

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.

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

For those interested for the solution in Windows 10, here is my configuration. It does not show "Terminate Batch" thing and works perfectly.
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

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

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

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

This is the only thing that worked for me:
Add a new package.json node run script command:
Create an NPM CONFIG (not a node config)
Select "start-watch" as the command
For me this worked for debugging / breakpoints without issues or additional headache.

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)?".

Do a npm install nodmemon -g
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.
You're good to go

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).
main.js is the starting point file for my Express application.

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)

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:

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

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

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

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

This is how I am running
Installed nodemon package
npm install -g nodemon # OR using yarn: yarn global add nodemon
From Webstorm terminal, run
nodemon index.js
This is how it will show running in terminal

Related

nodemon Internal watch failed: watch /Users/admin/Library/Application Support/Code/1.26.1-shared.sock Unknown system error -102

I installed nodemon in my Macbook Pro using sudo npm install nodemon -g command just today.
I am trying to run my Node JS code using the below command.
nodemon /Users/admin/nodejs/my-express-server/src/index.js
The script starts fine however immediately terminates with the below error.
[nodemon] Internal watch failed: watch /Users/admin/Library/Application Support/Code/1.26.1-shared.sock Unknown system error -102
I see few similar instances of questions already in Stack Overflow, however the error code/scenario is different. Also, I tried the answers from those similar questions and it didn't help.
So from the comments I got to know that you are running nodemon from your user directory or home directory. which is ~ or /Users/admin in your case.
Now nodemon watches EVERY directory and subdirectory for file changes. You can see that by watching dir(s): *.*
So when you are running:
nodemon /Users/admin/nodejs/my-express-server/src/index.js
You are running the index.js file but you are telling nodemon to watch every directory and file under the current working directory(which is /Users/admin in your case).
So, many Mac installations, application support files, basically every file you ever create by default goes to any directory under the home directory.
Now nodemon checks every file for change and the nodemon coudldn't put watch on vscode shared.lock file probably because of permission issue or the file is being opened by vscode itself.
Long story short(not really), go to the /Users/admin/nodejs/my-express-server/ folder and run nodemon from there.
cd /Users/admin/nodejs/my-express-server
nodemon src/index.js

What is difference between node and nodemon?

in my package.json I am using
"scripts": {
"start": "node app.js"
},
but if I use nodemon replace with node app.js like
"scripts": {
"start": "nodemon app.js"
},
then what will happen? Because when I got any error at server side, other API also close working. So I think it happen because I use node app.js if I use nodemon app.js than server will restart or not.
When you develop a node app and you make some changes, to see them in effect you have to restart the server.
When you launch your node.js application with Nodemon it will monitor for any changes and automatically restart the server, improving your productivity.
Nodemon is a utility that will monitor for any changes in your source and automatically restart your server. Perfect for development. Install it using npm.
npm install -g nodemon
How to use nodemon?
nodemon "filename" ignore the quotation and place name of the server file.
Nodemon:
monitors for any changes in your Node.js application
automatically restarts the server,
saving time and tedious work.
it's one way to make your development efficient with Opn:
Opn is a dependency that opens web browser links, files, and executables. We will be using Opn to automatically open a web browser to our local host every time our server restarts.Install with npm
npm install opn.
How to use node?
node "filename" ignore the quotation and place the filename (ex app.js ,server.js)
node:
no automatic restart the server every time you do the tedious work
no monitors for any change
nodemon is like a live-server for your node application. any changes made in your node application will get reflected as server will restart again.
as stated here :
nodemon will watch the files in the directory in which nodemon was
started, and if any files change, nodemon will automatically restart
your node application.
nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected.
To use nodemon, replace the word node on the command line when executing your script.
In terminal,instead of typing node app.js,you can type: npm start
In package.json file,you can change it to:
"scripts": {
"start": "nodemon app.js"
},
In short,it is like a live server for node js, like we have in HTML & CSS.
When you are using node you have to restart on your own to see the changes you made But nodemon watches the particular path for any changes.If you make any changes in your file, nodemon will restart it for you.
when we install node, we will get automatically node and npm global variable.
for using nodemon you need to install it
npm install -g nodemon
we can access files with node as well but each time when we do changes we need to stop server and restart it.
node "filename" // provide filename
but if we accessing file with nodemon you no need to stop server and restart it only one line of command will save restart server time
nodemon "filename" // provide filename
this one line helps you saving lot of development time and test your sample javascript code
Nodemon stands for Node Monitor.
When you run a server using the command node index.js, after every change in your code you have to again run the node index.js command and reload the page to see the changes. Nodemon solves this problem for you. It auto-updates the server for you.

Nodemon not working anymore . Usage: nodemon [nodemon options] [script.js] [args]

nodemon always worked for me. I always did nodemon server and it would run the server file and watch for updates and node would restart. But now when I do it, I get this in the cmd (I use windows):
Usage: nodemon [nodemon options] [script.js] [args]
See "nodemon --help" for more.
I tried uninstalling and reinstalling nodemon globally but still get the feedback. now I have to restart the server with regular node on every update.
EDIT:: This is what it looke like when i type in dir and press enter
05/29/2016 05:55 PM <DIR> .
05/29/2016 05:55 PM <DIR> ..
05/29/2016 05:35 AM <DIR> node_modules
05/29/2016 02:20 PM <DIR> public
05/24/2016 09:30 PM 2,836 server.js
05/29/2016 12:05 AM 3,513 server2.js
05/30/2016 12:41 AM 3,651 server3.js
05/29/2016 05:55 PM <DIR> views
3 File(s) 10,000 bytes
5 Dir(s) 650,802,348,032 bytes free
Are you sure your server file is in the folder you are in? Run dir and make sure the file you expect is in the directory before running the command. If the file you are trying to run is not present in the current directory, nodemon will spit out the usage message.
If your file is in the directory, try executing with the full file extension -- nodemon server.js
Make sure that when you are running the command nodemon server.js then you are inside the same directory in which your server file is.
This was the error that I was making while running the command it only appears when the nodemon is unable to find the file which it has been told to run after every save.
make sure you are running nodemon command in that particular directory else,you need to check the directory first wheather you are into it or not ,or cd thatDirectory ,and then run the nodemon index.js
Make sure there is a node_modules folder in your project directory. If it's not there ,kindly install the folder with this command - npm install
**one of the two important reasons of that error are
1.You have not installed npm packages in right directory.
2.U r running ur server in wrong directory or wrong folder.
**
Just ensure you are in the right directory where the nodemon package was installed. That should resolve the issue

Grunt.js Installation Issue - Command Not Found

I'm trying to get grunt.js set up on my work machine. Now I've managed to get it set up at home, so I pushed my repository, then cloned it on my work machine, however despite troubleshooting this to death I've always run into the same issue when I come to try and run the command on my work computer;
sh.exe": grunt: command not found
So some background and explanation;
I'm using Aptana 3.0 and running all my commands through the terminal. (This applies to my home and work computer)
I cloned the "working" repository and put it in a folder on my work machine, so I have my package.json and gruntfile.js files inside said directory. These work fine on my home computer and I am able to run the watch task set up in my gruntfile.js successfully at home.
I've run npm install grunt-cli -g and npm install inside my project on my WORK computer and installation has been successful each time. My only error messages on either are a lack of description and a repository field which, to my knowledge these aren't mandatory?
The node modules folder inside my repository indicates I have the following installed (as per my package.json)
grunt
grunt-contrib-compass
grunt-contrib-uglify
grunt-contrib-watch
matchdep
Now I'm pretty green to this command line stuff, so I may have overlooked something very obvious but I feel like I've tried every guide going to get this thing to work.
Despite running through the getting started steps/installing grunt documentation repeatedly, it seems no matter what I do the terminal will not pick up grunt as a recognized command.
Am I stupid or is this some other issue?
EDIT 1: contents of my package.json:
{
"name" : "xxxxxxxxx",
"version" : "xxxx",
"dependencies" : {
"grunt":"~0.4.1",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-compass": "~0.5.0",
"grunt-contrib-uglify": "~0.2.2",
"matchdep": "~0.1.2"
}
}
This is happening because you are using the Aptana Terminal, which needs the PATH variable to work out what is meant by grunt etc. A normal cmd prompt would work fine with the command npm install grunt-cli -g but in this context the terminal is unaware of what grunt is.
As per the following existing answer, you need to set up your Windows PATH variable to make the Aptana Terminal aware of the npm directory: https://stackoverflow.com/a/19137584/463205
C:\Users\Username\AppData\Roaming\npm
Closing the terminal and reopening it after setting the PATH correctly should enable you to run the command successfully.
Try to run
npm install grunt-cli -g
On your home computer.
-g means - install Grunt globally (not in the project node_modules folder), so it'll add grunt command to the bin folder which is used by nodejs console ( and you need to run node.js command prompt, not just arbitrary cmd)

Browserify command not found

Quick question, when I run browserify index.js -o app.js from mac terminal, I get command not found. I have done npm install -g browserify but still no luck. Any idea why I am getting this?
Thank you
It was easier for me to do a gist than to paste here:
https://gist.github.com/pertrai1/4ccf77e7b31cb5628b5d
Just install it in a global space like this if you need to run it from the command line.
npm install browserify -g
You may need to run
npm uninstall browserify -g fist just to be sure you don't have false aliases.
Add this to your ~/.bashrc or equivalent:
export PATH=$PATH:~/.npm-global/bin/
Then, to actually have this take effect in your terminal session, execute source ~/.bashrc.
At this point you can execute browserify, as well as potentially many other commands. Check out ~/.npm-global/bin/ to see what's become available.
I could not get browserify to work either.
Running ~/.npm/bin/browserify does work.
Other packages seem to run fine (phantomjs for instance).
A workaround fix seems to be adding alias browserify='~/.npm/bin/browserify' to your .bash_profile
It is an old post but I believe people are still facing the same problem, like me.
This was how I solved my problem:
<your project folder>/node_modules/browserify/bin/cmd.js main.js -o bundle.js
If you install locally npm install browserify, you can use this method to execute the browserify command.
node_modules/.bin/browserify
For example:
broweserify command example
Extra tips:
Add this command to your packages.js file:
...
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"bundle": "node_modules/.bin/browserify index.js > bundle.js"
},
Then everytime you want to bundle you file just hit npm run bundle
Hope it helps you guys out there..
If for some reason the browserify command has not been installed at all (can happen for example if you're running Homebrew on old unsupported Mac OS X versions), an alternative is to call it via node, for example:
export NODE_PATH=/usr/local/share/npm/lib/node_modules
node -e 'require("browserify")("input.js").bundle().pipe(fs.createWriteStream("output.js"))'
As a Mac user I had to add
export PATH=$PATH:/usr/local/Cellar/node/13.6.0/bin/
in ~.bash_profile
Why Cellar path i dont know.

Categories

Resources