nodemon command is not recognized in terminal for node js server

时光总嘲笑我的痴心妄想 提交于 2019-11-29 22:43:08

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

Alok Prusty

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

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

then write

npm run server
Raju Singh
  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 .
    

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 nodemon -g

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

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

This line solved my problem in CMD:

npm install --save-dev nodemon

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

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

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

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

This worked for me.

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.

Amol Kamble

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

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": "node server.js"
 },

and after that just run command

npm run server

and your nodemon will start working properly.

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.

Just install Globally

 npm install -g  nodemon

It worked for me on Windows 10.

nodemon app.js
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!