简体   繁体   中英

After I installed nodemon by "npm i nodemon" , when I tried to run it by "nodemon server.js" , it gives me this error. What should I do?

Screenshot form VS code terminal 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.

I just meet that question.

First , you should make sure that you had installed nodemon in a global way ( npm install -g nodemon ), and make sure global package dir is in the environment variables.

Secondly , you should RESTART VScode if you are opening it now. I spent lots of time to make sure the previous one, but it still fails, then when I restart VScode, everything is fine!

Try to install nodemon globally: https://github.com/remy/nodemon

npm install -g nodemon 

and edit Your package.json for example like that:

"scripts": {
    "start": "node server",
    "dev": "nodemon server"
  },

then in terminal enter the command =>

npm run dev 

It should works for You now;-) Good Luck and Best regards !

Below are some solutions

  1. This is how you can install nodemon
npm install -g nodemon

after that you have to run this command: npm run dev here dev is (script) server name like

{  
"main": "app.js",
"scripts": {
    "dev": "nodemon app.js"
  },
}
  1. after that if you are facing error like " 'nodemon' is not recognized as an internal or external command, operable program or batch file. " Then after install nodemon globally write below command:
npm config get prefix

in output you will get PATH and then past this path in to the Environment Variables and it solved

Restart the terminal and run this command

nodemon run dev

I hope after that it will work properly:)

I just had to use npx instead of npm for eg - npx nodemon <server.js>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM