Resolving Nodemon Command Not Found Error in Node.js

When you try to use Nodeman, you can trigger the error “Nodemon command not found”. Nodeman, a wonderful Node.js tool lets you concentrate on writing code. You are prone to face this error if you are a beginner. In this tutorial, we will learn what causes this error and how to fix it.

Why Do We Encounter This Error?

You are getting the Nodemon error because the Nodemon utility is incorrectly installed or not installed on your PC. It may also occur if you installed the Nodemon tool locally on your PC rather than globally.

Nodemon is a tool in Node.js that can help you with your workflow. Typically, when you make changes to your code, you must execute “node app.js” to apply changes. However, Nodemon does this automatically, allowing you to focus on writing code.

Nodemon requires no changes to your code or development process. It is simply a substitute wrapper for the node. If you want your code to reload automatically anytime you make changes, you must replace “node” with “nodemon”.

The following errors indicate a problem with the installation of the Nodemon package:

  • Nodemon command not found on Windows 10
  • Nodemon command not found yarn
  • Nodemon command not found zsh
  • Nodemon command not found on Visual Studio Code

If you do not perform it right, you will get the “command not found” error across all the platforms.

Also Read: How to fix [nodemon] app crashed – waiting for file changes before starting.

Steps to Solve the Error

To resolve the Nodemon command not found error, install the Nodemon package globally. Other options include reinstalling the Nodemon and setting the correct variable location. If nothing further works, update the package.json file. Let’s see each of them in detail.

1. Install Nodemon Globally

Make sure Nodemon is installed globally by executing the following command.

npm install -g nodemon

The -g flag installs Nodemon globally, so it may be accessed from any directory in your terminal.

2. Check Node.js Installation

Verify that Node.js and NPM are correctly installed. There are chances of problems with Node.js or NPM installation which might arise sometimes. You can verify the versions with:

node -v

npm -v

If these commands do not fetch the versions, you will probably need to reinstall Node.js and NPM.

Also Read: A Beginner’s Guide to Installing a Specific Version of NPM Package.

3. Verify Nodemon Installation

Once the Nodemon is installed, ensure that it is correctly installed by running:

nodemon -v

This will indicate the version of Nodemon installed. If you continue to receive the error that ‘Nodemon command not found’, this suggests that Nodemon has not been added to the system PATH.

4. Check System PATH

Make sure that the location where Nodemon is installed is in your system’s PATH. This enables the terminal to locate the ‘nodemon’ feasible. To check if Nodemon is installed in the system’s PATH, follow these steps:

For Windows:

Open Command Prompt and type:

echo %PATH%

This command will display the entire PATH variable.

For macOS & Linux:

Open Terminal and type:

echo $PATH

This command will display the entire PATH variable.

In both cases, we will see a list of directories which is separated by colons(‘:’). If the location where Nodemon is listed is in the PATH variable, then it is accessible from the terminal and if not, you need to add it to the PATH variable manually.

5. Check NPM Scripts

If you run your Node.js server with NPM scripts, ensure the ‘nodemon’ command is rightly specified in the “scripts” section of the package.json file.

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

6. Trying Without Global Installation

If you don’t want to install Nodemon globally, you may install this as a dev dependency on your project.

npm install --save-dev nodemon

Then use it in your NPM scripts:

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

After following these instructions, you should be able to run the ‘nodemon’ command in the terminal without receiving any error.

Conclusion

I hope you have found this tutorial useful. In this tutorial, we have learned about why we get the Nodemon command not found error. There are various situation that leads to this such as improper installation, wrong variable path, etc. To solve these errors we have covered multiple steps like installing Nodemon globally or setting the correct system path.

Reference

https://stackoverflow.com/questions/17975999/i-can%C2%B4t-install-nodemon-globally-nodemon-not-recognized

Adarshita Gupta
Adarshita Gupta
Articles: 10