169

I am doing node.js server setup from https://scotch.io/tutorials/authenticate-a-node-js-api-with-json-web-tokens. I am new in node.js. I am installing npm install nodemon --save. But when I am run the server with this nodemon server.js.
In the terminal showing:

nodemon is not recognized as internal or external command, operable program or batch file

enter image description here

node server.js command is working and started the server, But nodemon command is not working.

I am set up the node js server from https://scotch.io/tutorials/authenticate-a-node-js-api-with-json-web-tokens video.

I don't know why it is not working I have tried some command for the install nodemon.

npm install -g nodemon 
npm install -g nodemon --save 
npm install --save-dev nodemon 
npm install -g nodemon@debug 

npm install -g --force nodemon

I have seen one link I can´t install nodemon globally, "nodemon" not recognized, But I don't know how to set the path because of my project location in D drive.

I want to run nodemon server.js. How can this be done?

starball
  • 20,030
  • 7
  • 43
  • 238
Varun Sharma
  • 4,632
  • 13
  • 49
  • 103
  • Note to future readers: do not post images of text. Post the text as text with [whatever formatting is appropriate](https://stackoverflow.com/editing-help). [See here](https://meta.stackoverflow.com/a/285557/11107541) for why. – starball Dec 17 '22 at 05:11
  • See also: https://www.npmjs.com/package/nodemon; the last paragraph of the 'Installation' section. – Alex Mandelias Aug 22 '23 at 11:04

29 Answers29

389

You need to install it globally

npm install -g nodemon
# or if using yarn
yarn global add nodemon

And then it will be available on the path (I see now that you have tried this and it didn't work, your path may be messed up)

If you want to use the locally installed version, rather than installing globally then you can create a script in your package.json

"scripts": {
    "serve": "nodemon server.js"
  },

and then use

npm run serve

optionally if using yarn

# without adding serve in package.json
yarn run nodemon server.js
# with serve script in package.json
yarn run serve

npm will then look in your local node_modules folder before looking for the command in your global modules

ndonohoe
  • 9,320
  • 2
  • 18
  • 25
  • What is not working? The script using local install? – ndonohoe Nov 01 '16 at 12:15
  • Yaa. Ihave installed nodemon. I putted script in package.json file. And after run npm run serve. After all then run nodemon server.js but not working. – Varun Sharma Nov 01 '16 at 12:21
  • package.json: { "scripts": { "serve": "nodemon server.js" }, "name": "node-site", "version": "1.0.0", "description": "", "main": "server.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "express": "^4.14.0", "nodemon": "^1.11.0" }, "devDependencies": { "gulp-nodemon": "^2.2.1", "nodemon": "^1.11.0" } } – Varun Sharma Nov 01 '16 at 12:25
  • Can you clarify "not working"? Is there an error? Does nothing happen? – ndonohoe Nov 01 '16 at 12:45
  • It may be because you have two sets of scripts in there, you have to have all scripts in one scripts object – ndonohoe Nov 01 '16 at 12:46
  • Yes, after making above settings it's working like a charm. Thanks ! – Akash5288 Dec 03 '18 at 20:10
  • This worked for me, however, the cli command was `nodemon.cmd .\yourFIleName.js` in my vscode running in windows machine. – Gel Jan 03 '22 at 02:39
57
  1. Install nodemon globally:

    C:\>npm install -g nodemon
    
  2. Get prefix:

    C:\>npm config get prefix
    

    You will get output like following in your console:

    C:\Users\Family\.node_modules_global
    

    Copy it.

  3. Set Path.
    Go to Advance System Settings → Environment Variable → Click New (Under User Variables) → Pop up form will be displayed → Pass the following values:

    variable name = path,
    variable value = Copy output from your console
    
  4. Now Run Nodemon:

    C:\>nodemon .
    
double-beep
  • 5,031
  • 17
  • 33
  • 41
Raj Kumar
  • 758
  • 6
  • 12
  • This works!! This is was I was looking for. Thank you – yashjain12yj Feb 25 '19 at 09:10
  • this worked for me. Actually i have windows and needed to fix the environment variables. Thanks :) – Laveena Jul 08 '20 at 17:01
  • This Works Too!!!!!!!! i was working on a ExpressJS Project. I was using npm scripts, Then i Started to search On Google. I found This Link on Google, I Just Use npx nodemon on my laptop. But i wanted to use only nodemon , And Then i found This – Shridhar Sagari May 18 '21 at 17:03
42

No need to install nodemon globally. Just run this npx nodemon <scriptname.js>. That's it.

pritam ghosh
  • 530
  • 4
  • 6
31

First, write npm install --save nodemon then in package.json write the followings

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

then write

npm run server
Deepak A
  • 1,624
  • 1
  • 7
  • 16
Alok Prusty
  • 330
  • 3
  • 4
  • This worked! Thanks a lot. Just a query, nodemon prevents us from restarting the server file, but we still have to refresh the browser. Can the browser refresh on its own, like it does in angular ? – Rahul Sharma Apr 19 '18 at 09:47
  • If you still get the error after doing this, you could try deleting the node_modules folder and re-running `npm i` before running the app again. – Chris Halcrow Feb 26 '21 at 05:01
11

I was facing the same issue. I had installed nodemon as a dev-dependency and when I tried to start the server it gave the message that

nodemon is not recognized as internal or external command, operable program or batch file

Then I installed it globally and tried to start the server and it worked!

npm install -g nodemon
Community
  • 1
  • 1
adityaekawade
  • 312
  • 4
  • 5
9

To use nodemon you must install it globally.

For Windows

npm i -g nodemon

For Mac

sudo npm i -g nodemon

If you don't want to install it globally you can install it locally in your project folder by running command npm i nodemon . It will give error something like this if run locally:

nodemon : The term 'nodemon' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling
of the name, or if a path was included, verify that the path is
correct and try again.

To remove this error open package.json file and add

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

and after that just run command

npm run server

and your nodemon will start working properly.

Amit Kumar
  • 169
  • 1
  • 10
  • 1
    Wrong. Your script should say { "server": "nodemon server.js" } – joedotnot Aug 15 '19 at 10:28
  • this worked for my case, where I just want to run a simple js file. But the nodemon cli command was automated to `nodemon.cmd .\yourfileName.js` – Gel Jan 03 '22 at 02:37
9

This may come to late, But better to say somthing :)

If you don't want to install nodemon globbaly you can use npx, it installs the package at run-time and will behave as global package (keep in mind that it's just available at the moment and does not exist globally!).

So all you need is npx nodemon server.js.

  • npx can be used out of the box from npm@5.2.0 version and up.
Yaron Miro
  • 99
  • 1
  • 4
7

Does it need to be installed globally? Do you need to be able to just run nodemon server.js ? If not, you could always just call it from your local project directory. Should be here:

node_modules/.bin/nodemon
Larry Turtis
  • 1,907
  • 13
  • 26
7

I have fixed in this way

  1. uninstall existing local nodemon

    npm uninstall nodemon

  2. install it again globally.

    npm i -g nodemon

Saad Abbasi
  • 745
  • 11
  • 25
  • 1
    This works perfect. In my environment (Windows Server) with 4 programmers connected to the same server, coding through RDP. Thanks Saad. – Danielle Oct 01 '21 at 16:23
  • this worked for my case, where I just want to run a simple js file. But the nodemon cli command was automated to `nodemon.cmd .\yourfileName.js` – Gel Jan 03 '22 at 02:38
7

I had the same error a few minutes ago and this is how I've solved it:

1. Install "nodemon" Globally

npm install nodemon -g

2. Then you need to add the npm path to the environment variables

To find the path do this in the terminal:

npm config get prefix

You'll get the output that looks like this: C:\Users\user\AppData\Roaming\npm

If you're not sure about how you can update environment variables on Windows, check this out: Here

3. Run the app again with "nodemon" Before you run the app, create a new terminal to make sure that the terminal recognises the changes in the environment variables. Then run: ex:

nodemon server.js

Dharman
  • 30,962
  • 25
  • 85
  • 135
Cyebukayire
  • 795
  • 7
  • 14
6

This line solved my problem in CMD:

npm install --save-dev nodemon
Bakos Bence
  • 243
  • 5
  • 7
6

I tried installing the nodemon globally but that doesn't worked for me. whenever i try to run it always shows me the error:

nodemon : The term 'nodemon' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling
of the name, or if a path was included, verify that the path is
correct and try again.

2. I have found two solutions for this

solution 1:

What i have tried is to update the "scripts" in package.json file and there i have added

"server": "nodemon app.js"

above line of code and after that

npm run server

Soluton 2:

  1. Press the Windows key.

  2. Type "Path" in the search box and select "Edit the system environment variables"

  3. Click on "Environment Variables" near the bottom.

  4. In the "System Variables" section double click on the "Path" variable.

  5. Click "New" on the right-hand side.

  6. Copy and paste this into the box (replace [Username]):

C:\Users[Username]\AppData\Roaming\npm

  1. restart your terminal and VSCode.

  2. Then type nodemon app.js to run the nodemon

i applied solution 2 as we just need to run nodemon [filename.js]

Shubham Kumar
  • 295
  • 3
  • 13
6

It is better to install nodemon globally instead as dev dependency to the project.

npm install -g nodemon

Official NPM CDN: Link

This package is used to monitor changes in the javascript files and re run the npm start so that it is easy to dev purposes.

5

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. try this link and follow it.fixing npm permissions https://docs.npmjs.com/getting-started/fixing-npm-permissions#option-2-change-npms-default-directory-to-another-directory

2

You can run your node app by simply typing nodemon It First run index.js You can put your entry point in that file easily.

If you have not installed nodemon then you first you have to install it by

npm install -g nodemon

If you got any permission error then use

sudo npm install -g nodemon

You can check nodemon exists or not by

nodemon -v
Shraddha Goel
  • 869
  • 7
  • 18
2

For me setting the path variables was enough for the solution:

Step 1) Install nodemon globally using npm install -g nodemon

enter image description here

Step 2) Set the ENVIRONMENT VARIABLES, by adding npm path the PATH variable

1) Open Control Panel, search for environment variable

enter image description here

2) Click open the environment variable enter image description here

3) Create new variable NPM set it with the path of npm as appears from the nodemon installation cmd output (as seen from nodemon installation screenshot):

enter image description here

4) Now add NPM variable to the PATH variables:

enter image description here

Step 3) Close the 'cmd' and open a fresh one and type nodemon --version enter image description here

Now we have the nodemon ready to use :)

Kailas
  • 7,350
  • 3
  • 47
  • 63
2

This issue is also possible if running scripts is disabled on the system. In order to enable it:

  1. Open Windows PowerShell with Run as Administrator

  2. Execute:

    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

  3. npm install -g nodemon

  4. nodemon app

sauravjoshi23
  • 837
  • 11
  • 9
  • Thanks... this worked for me, I could run nodemon from windows cmd but it was not working on visual studio code terminal nor powershell, but after execute you solution it works on all 3 consoles (I think VSC terminal is a powershell console because it has "PS" at start of prompt line). – Mauricio Santamaria Feb 04 '23 at 16:18
2

First you need to install nodemon globally by using this command: "npm i -g nodemon" (for Windows) and "sudo npm i -g nodemon" (for Mac) then run "nodemon app.js" Now you will be fine.

1

Just had the same problem after creating a new user profile on my development machine.

The problem was that I wasn't running the console (command prompt\powershell ISE) as admin.

Running as admin solved this problem for me.

Jim Jimson
  • 2,368
  • 3
  • 17
  • 40
1

Just install Globally

 npm install -g  nodemon

It worked for me on Windows 10.

nodemon app.js
Prathamesh More
  • 1,470
  • 2
  • 18
  • 32
1

The Set-ExecutionPolicy cmdlet's default execution policy is Restricted for Windows. You can try installing nodemon by setting this policy to Unrestricted.

execute command : Set-ExecutionPolicy Unrestricted and then try installing nodemon and execute command: nodemon -v

Mayur
  • 53
  • 1
  • 10
1

Even I had the same issue, the following command worked for me.

npm install -g nodemon
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34552557) – Cihan Yakar Jun 21 '23 at 12:56
0

Run this command:

npm install nodemon -g

Now it will install the nodemon but the problem with my case is that it is installing nodemon somewhere else.I added Nodejs path from (ProgramFiles(x86)) but that did not worked so i found another solution.

  • Run above command
  • There will be a path shown during installation where nodemon is installed,then [Kindly go to below link to see the path][1]

    [1]: https://i.stack.imgur.com/ld2sU.png

  • Copy the path upto npm and set it to environment variable
  • Now try the below command,hopefully it will run

      nodemon YourAppName.js
Junaid
  • 13
  • 1
  • 3
0

All above options are failed, I got the permanent solution for this. Add below line in package.json under dependencies and run npm install. This will add nodemon package to node_modules and there you go, enjoy the coding.

"nodemon": "^1.17.*"
gil
  • 1,318
  • 12
  • 19
  • 3
    Welcome to Stack Overflow. When answering an older question with existing answers it is useful to explain what new information your answer brings. This answer doesn't appear to be showing a global install, it references a specific version (so it won't age well), and it doesn't answer the question that was asked in that it doesn't show how to enable the command. – Jason Aller May 18 '19 at 19:42
0

Try in your packge.json: put "./node_modules/.bin/nodemon" instead of just "nodemon". For me it works.

moshi
  • 280
  • 4
  • 16
0

Step 1: $ npm install nodemon --> install nodemon on your project

Step 2: Add serve in script on package.json file as:

"scripts": {
    "serve": "nodemon app.js" // you can change file name accordingly 
}

Step 3: $ npm run serve

Amitesh Singh
  • 162
  • 2
  • 7
0

The following worked for me on windows 11.

  1. Type npm install in the terminal. (Within the same directory as the project)
  2. Then type npm run serve to run the application from the default browser.

enter image description here

minTwin
  • 1,181
  • 2
  • 21
  • 35
0

I was having this issue using the terminal from vscode after installing globally and trying other solutions and the following worked:

  1. Open a new terminal outside of vscode (alt+r -> cmd -> enter)

  2. Set directory to the folder containing the express app.js: cd C:\Users\<username>\Desktop\<project-name>\express

  3. Run nodemon app.js

Should work

DonCarleone
  • 544
  • 11
  • 20
-2

Remove nodemon because it's a dev dependency and use node instead of it.

"scripts": {
     "start": "node server.js"
 },

This worked for me.