57

I want to use nodemon for monitoring my node.js app's, then I execute the next line command:

npm install -g nodemon 

or

npm install nodemon -g

When I move to my app folder and try to to

nodemon app.js

The system tells to the next:

"nodemon 'is not recognized as an internal or external command, program or batch file.

Ali Nem
  • 5,252
  • 1
  • 42
  • 41
RMontes13
  • 2,138
  • 3
  • 16
  • 23

15 Answers15

150

Since node prefix is not in the PATH ENV variable , any of the globally installed modules are not getting recognized.

Please try this.

Open cmd prompt

npm config get prefix

append the resulting path to PATH env variable.

Now you should be able to run nodemon from any location.


This is what i have done on my local machine


C:\>npm config get prefix
C:\Users\username\AppData\Roaming\npm

C:\>set PATH=%PATH%;C:\Users\username\AppData\Roaming\npm;

C:\>nodemon
 31 Jul 22:30:29 - [nodemon] v0.7.8
 31 Jul 22:30:29 - [nodemon] to restart at any time, enter `rs`
 31 Jul 22:30:29 - [nodemon] watching: C:\
 31 Jul 22:30:29 - [nodemon] starting `node `
 ^CTerminate batch job (Y/N)? Y
Chandu
  • 4,581
  • 2
  • 17
  • 13
  • In my case I also had to add '/bin' after this config path, placed the result in `.bashrc` (using export PATH etc). – PascalVKooten Feb 23 '16 at 18:36
  • sometime Appdata folder is hidden you can just type C:\Users\username\AppData\Roaming\npm in windows folder path. username should be your computer name . – Himanshu sharma Jun 27 '17 at 14:00
  • I am not able to install nodemon using yarn. Is it same as `npm install -g nodemon` ? – Lokesh Pandey Jul 28 '18 at 04:19
  • It worked for me when I added the path somewhere in between the existing PATH, did not work when the path was added to the end of PATH variable. Also all the CMD/ Terminal windows need to be restarted. – Siva Aug 10 '19 at 14:31
  • @Siva Please follow this link https://www.computerhope.com/issues/ch000549.htm for the settings to persist terminal restarts. – Chandu Aug 12 '19 at 12:23
27

I also got same error as you with this command:

$ sudo npm install -g nodemon

I just really switched as "root" and then just ran:

$  npm install -g nodemon

I think npm has a bug to not work with sudo, but it works fine when you are really "root".

benomatis
  • 5,536
  • 7
  • 36
  • 59
user1501382
  • 1,187
  • 14
  • 18
  • 1
    Works for me too. I already had Roaming\npm on my path. It appears that installing npm with the -g is needed on windows. (document says -g or -global is needed to add the bin of the command line utility to the PATH) – arviman Nov 11 '14 at 09:39
3

Single line solution In terminal

npm install -g --force nodemon

Rinold
  • 343
  • 1
  • 2
  • 12
3

There is a problem with integrated terminal of vs code. when I try in external terminal nodemon works. But in integrated terminal, it gives bash: nodemon: command not found error.

so here is my solution

install nodemon as development dependency

npm install --save-dev nodemon

and change package.json of the project

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "nodemon": "./node_modules/.bin/nodemon"
  },

to run nodemon type into terminal in project folder

npm run nodemon
1

Mine was I went to Control Panel and Repair the NodeJS app and tried to install again with npm install -g nodemon and now it works. Maybe you mixed up or something with Node.

RJB
  • 95
  • 3
  • 15
1

check out here :-

npm install -g nodemon

and then run

$nodemon server.js
Ajay Kumar
  • 4,864
  • 1
  • 41
  • 44
1

You won't need to install nodemon anymore, since Nodejs has finally introduced its --watch feature which restarts the process when an imported file is changed.

node --watch index.js

https://nodejs.org/en/blog/release/v18.11.0/

0

Linux users: I would highly suggest not using sudo or root user to install npm packages. This could become a security problem especially on a production system. I would also suggest not trying to hack permissions as I have hosed an Ubuntu system by not reading the warning on the npmjs procedure.

It would be better to configure npm to use a folder owned by the current user. Simplest approach

wget https://raw.githubusercontent.com/pcnate/npm-configure/master/add-npm-global.sh -q -O - | bash
npm install -g nodemon

Or get the code script on github to see how it works

See details on the npmjs website

pcnate
  • 1,694
  • 1
  • 18
  • 34
0

On Windows, I was having issues installing nodemon directly from the Command line. Downloaded Cygwin and I was able to npm install nodemon instantly.

user111
  • 397
  • 3
  • 13
0

You can add path to node packages in System Path variable. Add "C:\Users\UserName\AppData\Roaming\npm".

kapil
  • 1,710
  • 1
  • 15
  • 12
0

Even after adding path to System Path variable it did not work for me using nodemon. Then i used npm run serve to run the server. now it is up and running. Btw i am a windows user

Charitha Goonewardena
  • 4,418
  • 2
  • 36
  • 38
0

This command worked for me.

If your global installation didn't work then install it in your development dependency.

npm install --save-dev nodemon
Bhanu Sengar
  • 372
  • 2
  • 10
0

Updated

After Path settings we also need to type in the following commands

Set-ExecutionPolicy Unrestricted

what this command enables running scripts on the system

warmachine
  • 376
  • 1
  • 8
0

I think some of us can't reach global environments without admin privileges. If you tried everything and it's still not working, try running VSCode as administrator. It worked out for me.

neiloth
  • 157
  • 1
  • 11
-1

had the same problem otherwise was just working fine a day ago. Very simple fix first check if nodemon exists on your system globally or not

To check

npm list -g --depth=0

If you don't see then install it npm install -g nodemon (g stands for globally)
If you see it still doesn't work then you need to configure environment variable I use Windows OS. On Windows navigate to

Control panel>System>Advanced System Settings>Environment Variables>double-click on PATH

Now check if you have this PATH C:\Users\yourUsername\AppData\Roaming\npm
If not, you will see some existing paths, just append to it separating with semicolon. That's it! Worked for me. For me node was installed in C:..\Roaming\npm and for you if the PATH is different, you will put in whatever applcable.

pulkit219
  • 77
  • 1
  • 5