154

I'm on a Mac running El Capitan. I have node v5.6.0 and npm v3.6.0. When I try to run nodemon, I get:

-bash: nodemon: command not found

I thought this may mean that I didn't have nodemon installed, so when I tried to install it using...

sudo npm install -g nodemon

...I get this:

npm ERR! Darwin 15.2.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g"     "nodemon"
npm ERR! node v5.6.0
npm ERR! npm  v3.6.0
npm ERR! path /usr/local/bin/nodemon
npm ERR! code EEXIST

npm ERR! Refusing to delete /usr/local/bin/nodemon: ../lib/node_modules/nodemon/nodemon.js symlink target is not controlled by         npm /usr/local
npm ERR! File exists: /usr/local/bin/nodemon
npm ERR! Move it away, and try again.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/brianeoneill/npm-debug.log

If it makes a difference, I'm trying to run nodemon on a project that uses Express v4.13.1

Thanks for any help you can offer!

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
Brian O'Neill
  • 4,705
  • 5
  • 22
  • 26
  • Have you uninstalled nodemon before trying to install it again globally? `npm uninstall nodemon` – Sterling Archer Feb 21 '16 at 00:49
  • 1
    I tried that and it didn't work. However, I just tried sudo npm install -g --force nodemon, and that seemed to do the trick. Thanks for your help!!!!! – Brian O'Neill Feb 21 '16 at 00:58
  • May be my solution helps you ;) https://stackoverflow.com/questions/46505121/bash-nodemon-command-not-found-windows-10/46507487#46507487 – Sergey Andreev Sep 30 '17 at 22:15

22 Answers22

245

I tried the following, and none worked:

npm uninstall nodemon

sudo npm uninstall -g nodemon

What did work was:

sudo npm install -g --force nodemon
Brian O'Neill
  • 4,705
  • 5
  • 22
  • 26
  • watch the following video from official docs site https://docs.npmjs.com/getting-started/fixing-npm-permissions . Will give you better insight about the issue. – Jinesh Feb 22 '16 at 12:48
  • 1
    recommendation to delete package : 1 - Remove line from package.json 2 - and type this command " node prone " – Dostonbek Oripjonov Sep 27 '19 at 06:21
121

If you want to run it locally instead of globally, you can run it from your node_modules:

npx nodemon

Alex Leibowitz
  • 1,364
  • 1
  • 8
  • 12
  • EDIT: sadly i have to use this command each and everytime i want to run my program instead of it installing nodemon locally. – Erik Russell May 23 '19 at 21:59
  • 1
    This works on Mac OSx like charm! Thank you! – Didierh May 29 '21 at 04:39
  • 2
    Thanks! For anyone having to run it manually every time, just add a new script in your package.json like so `"serve": "npx nodemon index.js"` and then just run with `npm run serve` – Web Dev Jul 20 '22 at 12:02
70

From you own project.

npx nodemon [your-app.js]

With a local installation, nodemon will not be available in your system path. Instead, the local installation of nodemon can be run by calling it from within an npm script (such as npm start) or using npx nodemon.

OR

Create a simple symbolik link

ln -s /Users/YourUsername/.npm-global/bin/nodemon /usr/local/bin

ln -s [from: where is you install 'nodemon'] [to: folder where are general module for node]

node : v12.1.0

npm : 6.9.0

Murphy
  • 849
  • 7
  • 6
52

I'm using macOS/Linux, the solution that works for me is

npx nodemon index.js 

I have tried every possibility, like uninstalling and installing nodemon, installing nodemon globally. restart the terminal, but it won't work.

don't try such things to waste your time.

Harsh Patel
  • 6,334
  • 10
  • 40
  • 73
33

in Windows OS run:

npx nodemon server.js

or add in package.json config:

...
"scripts": {
    "dev": "npx nodemon server.js"
  },
...

then run:

npm run dev
VnDevil
  • 1,321
  • 15
  • 13
15

I had the same exact problem, expect for Windows OS.

For me, running

npm install -g nodemon --save-dev

(note the -g) worked.

Maybe somebody else who has this problem on Windows will have the same solution.

user2407334
  • 887
  • 1
  • 10
  • 15
13

FOR WINDOW USERS

I tried every possible way but nothing worked for me.

What worked was:- npx nodemon server

FOLLOWING WILL BE THE OUTPUT:- enter image description here

Suprabhat Kumar
  • 645
  • 7
  • 13
11

For mac Users, use npx nodemon index.js

...
  "scripts": {
    "start": "npx nodemon index.js"
  },
...


> my-project@1.0.0 start
> npx nodemon index.js

Need to install the following packages:
  nodemon
Ok to proceed? (y) 
[nodemon] 2.0.13
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
Server Started on Port 8000
Thiago
  • 12,778
  • 14
  • 93
  • 110
8

For nodemon: not found command I tried with many links but was not working then i tried with the below steps it worked fine.

Follow this step it worked for me.

step1 : sudo su

step2 : npm install -g nodemon --save-dev

It is working fine.

syed
  • 606
  • 8
  • 11
8
sudo npm install nodemon --save-dev

Next package.json on and

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon app.js"
}

Type on terminal (command prompt)

npm start
ANAGH K R
  • 114
  • 1
  • 4
  • 1
    I always add it in package file under start, "start": "nodemon app.js" it works perfect, and great way of using nodemin – Eldlabs Dec 13 '22 at 07:53
8

Install nodemon:

sudo npm install -g nodemon

Run server:

sudo nodemon server.js
Pavneet Kaur
  • 729
  • 7
  • 5
6

I ran into the same problem since I had changed my global path of npm packages before.

Here's how I fixed it :

When I installed nodemon using : npm install nodemon -g --save , my path for the global npm packages was not present in the PATH variable .

If you just add it to the $PATH variable it will get fixed.

Edit the ~/.bashrc file in your home folder and add this line :-

export PATH=$PATH:~/npm

Here "npm" is the path to my global npm packages . Replace it with the global path in your system

Natesh bhat
  • 12,274
  • 10
  • 84
  • 125
6

In macOS, I fixed this error by installing nodemon globally

npm install -g nodemon --save-dev 

and by adding the npm path to the bash_profile file. First, open bash_profile in nano by using the following command,

nano ~/.bash_profile

Second, add the following two lines to the bash_profile file (I use comments "##" which makes it bash_profile more readable)

## npm
export PATH=$PATH:~/npm
Akarsh SEGGEMU
  • 2,011
  • 1
  • 15
  • 18
5

Just in case for those using Windows, you don't need sudo

npm i -g nodemon
MJ Montes
  • 3,234
  • 1
  • 19
  • 21
3
sudo su

then

npm install nodemon 

worked for me

Frank Hag
  • 327
  • 2
  • 6
3

Just writing what did worked for me - (on Windows machine, installing node locally to the project) if you do not want to install it globally (i.e without -g flag) you have to use

npx nodemon app

where app is your app.js is your program file to launch.

Arjit Sharma
  • 416
  • 5
  • 15
2

Make sure you own root directory for npm so you don't get any errors when you install global packages without using sudo.

procedures:- in root directory

sudo chown -R yourUsername /usr/local/lib/node_modules
sudo chown -R yourUsername /usr/local/bin/
sudo chown -R yourUsername /usr/local/share/

So now with

npm i npm -g 

you get no errors and no use of sudo here. but if you still get errors confirm node_modules is owned again

/usr/local/lib/

and make sure you own everything

ls -la

enter image description here now

npm i -g nodemon

will work!

Ahmed Younes
  • 964
  • 12
  • 17
2

Since Node v18.11.0 there is running in 'watch' mode using

node --watch

which restarts the process when an imported file is changed.

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

1

Following commands worked for me in my case

Open Windows Powershell and Run series of following Commands,

Get-ExecutionPolicy -List

Set-ExecutionPolicy Unrestricted

*Press Y for YES*

Set-ExecutionPolicy Unrestricted -Force

Here you Go.

Engr Saddam Zardari
  • 1,057
  • 1
  • 14
  • 27
0

In Windows git bash, I fixed it by restarting git bash

AliFurkan
  • 487
  • 5
  • 11
0

Put --exec arg in single quotation.

e.g. I changed "nodemon --exec yarn build-langs" to "nodemon --exec 'yarn build-langs'" and worked.

Masih Jahangiri
  • 9,489
  • 3
  • 45
  • 51
0

Funny, I even did, having similar problem:

node_modules/nodemon/bin/nodemon.js index

and it worked, but now I see is that the proper way is as in many comments in this section, using

npx nodemon index

Maybe someone will have some use of my solution, for instance I targeted 'mocha' test node modules on one project directly this way, so while probably not the best solution, it can be of use sometimes.

Gishas
  • 380
  • 6
  • 21