If you are a newbie and trying to install nodemon and getting “nodemon command not found“. You have landed on the right page. When I installed it, I encountered the same error and I looked on the internet for a solution. There are many solutions available but in this post, I will give you flawless solutions for all your problems about nodemon.
You would need npm and node js as a pre-requisite. I have already written an article on npm and node.js installation. You can refer to it and can come back to this post, once npm and node.js are installed.
All these below mentioned errors points to the same issues of nodemon package installation and can be solved by following this article step by step.
- nodemon command not found in macOS
- nodemon command not found in windows 10
- zsh command not found nodemon
- bash: nodemon: command not found in ubuntu
- nodemon command not found in cmd
- nodemon is not recognized as internal or external command, operable program or batch file
Why does nodemon not found error occurs?
- nodemon is not installed on your system or incorrectly installed
- Trying to run “sudo npm install nodemon -g” command and getting error
- Insufficient user access or permissions
- You have not installed nodemon globally
- In case of local install, package.json is messed up
- Path variable is not setup correctly for npm
Troubleshooting articles, you may find useful –
- Yarn command not found error
- Sudo command not found error
- Fix “mkvirtualenv command not found” error
- Nodemon command not found
- Nodemon app crashed – Waiting for file changes before starting
- Keytool command issues
- Cmake command errors
Solution-1 How to fix “nodemon command not found” error by installing package globally
The nodemon is not installed on your system or incorrectly installed is one of the main reasons to get nodemon command not found error.
If you will install the nodemon package globally by following this article step by step. Most of you will get your nodemon error sorted quickly.
I will show you how to install nodemon in different operating systems correctly.
1.1 How to install nodemon in Ubuntu or Mac OS correctly
- Make sure you have installed npm and Node js in your system and checked npm version. Check out my post on “npm command not found” error, in case you get the same.
- Check installed global packages using npm list command
$ sudo npm list -g --depth=0
If you don’t find the nodemon package in the list, then you must install nodemon first. For example, in my case, it is not installed as shown in the above image.
- Run npm command to install nodemon globally in system path.
$ sudo npm install -g nodemon
- You can also use option –force, in case of errors during installing nodemon.
$ sudo npm install -g --force nodemon
- In the case of “Yarn“, run –
$ sudo yarn global add nodemon
- Check nodemon version. I have nodemon 2.0.15 version installed.
$ sudo nodemon -v
If you can run the nodemon -v command without any issue, it means you have installed the nodemon package globally and correctly. You will not face any “nodemon command not found” error for sure.
Now you can run the server or your application js file as per your need. For the demo, I have created an index.js file that shows the “hello world” page on localhost port 3000.
$ sudo nodemon index.js
In case you don’t have server.js installed, you can do it simply by running the following command.
$ sudo npm install server
- Create index.js and paste this content
// Include the server in your file
const server = require('server');
const { get, post } = server.router;
// Handle requests to the url "/" ( http://localhost:3000/ )
server([
get('/', ctx => 'Hello world!')
]);
Run “node .” command
$ node .
and open the browser with localhost:3000. It will show you the “hello world” output. It means you are running the server successfully.
1.2 Install nodemon as a development dependency in Ubuntu
If you want to install nodemon as a development dependency, run –save-dev as an option. Then the package will appear in your dev dependencies.
- Install nodemon as a development dependency, if required
$ sudo npm install -g nodemon --save-dev
In case you are using Yarn, then use -D for development dependency.
$ sudo yarn add nodemon -D
In case you are trying to install nodemon locally, then run the following command from your node_modules. The npx command works for npm version 5.2 or greater.
*** npx command helps to run a command from a local or remote npm package.
npx nodemon [your app.js]
For example, in my case
$ npx nodemon index.js
Note – The local installation of nodemon can be run by calling it from within an npm script (such as npm start
) or using npx nodemon
1.3 How to install nodemon in Windows correctly
Like Ubuntu or Mac, the same steps apply to Windows 10 also. The only difference is you don’t need to use the sudo command. I would suggest you refer to this article from starting to get more insight. I have explained everything in step 1.1 for your better understanding.
In Window 10, You must be an admin or need to open the command prompt as elevated rights.
- Open command prompt
- Make sure you have npm and node js installed in your Windows 10 server and check version using npm -v and node -v command. In case of issues, follow this article to install npm and node js in Windows.
- Change to directory where you want to install nodemon. I am using default system32 location. You can use your own user directory e.g C:\users\”username”.
- Run following command to install nodemon globally in Windows 10.
C:\> npm install -g nodemon ##in case of Yarn C:\> yarn global add nodemon
If you have installed nodemon earlier and getting errors or conflicts, you can run the following command using the –force option in Windows 10.
# Use --force option, in case of errors c:\> npm install -g --force nodemon
If you want to install nodemon as a development dependency in Windows 10, run the npm install command with –save-dev option.
c:\> npm install -g nodemon --save-dev
To run nodemon locally with npm 5.2 or higher version
npx nodemon [your app.js]
For example, in my case to run the server, any one of the following commands will work. Because I already have server.js installed. The Index.js file is having a sample code of “hello world” as a home page.
c:\ npx nodemon server # OR c:\ npx nodemon index.js
- To validate it. open the browser and you will see your application. In my case, it’s the “Hello World” code in Index.js and I can see it very well.
In case you don’t have a server installed on your Windows 10, Run these commands –
c:\ npm install server
Create Index.js file in the same folder with the following “hello world” code to test server is running fine in Window 10.
// Include the server in your file
const server = require('server');
const { get, post } = server.router;
// Handle requests to the url "/" ( http://localhost:3000/ )
server([
get('/', ctx => 'Hello world!')
]);
Run server.js by running any one of the following commands –
C:\> node . or c:\> npx nodemon index.js
Solution-2 Insufficient user access or permission during installation
Make sure you use either root privileges or sudo access users to install nodemon. Otherwise, you may get errors during the installation of the nodemon package and later when you will try to run your projects, it may result in a “nodemon command not found” error.
Check out the following command to install nodemon with sufficient privileges globally –
$ sudo su $ npm install -g nodemon # OR $ sudo npm install -g nodemon
If you don’t have the option to install nodemon using sudo or root access, then make sure you have access to npm directories. Ask your Linux admin to provide ownership to “your username” on NPM directories.
Following commands can help you get ownership access to NPM directories.
$ sudo chown -R yourUsername /usr/local/lib/node_modules
$ sudo chown -R yourUsername /usr/local/bin/
$ sudo chown -R yourUsername /usr/local/share/
Then you can install nodemon globally without sudo or root access using your own user.
$ npm install -g nodemon
- In the case of Windows 10, Admin user or Elevated access on command prompts will make sure, you will not get any nodemon command not found error after installing nodemon.
Solution-3 Path Variable is not setup correctly
If you have installed the nodemon globally and still getting the error of “nodemon command not found“. Then try to set up the path variable of npm. Although it is set up by default during npm installation, sometimes any other package can conflict and can mess up with system variables.
- Open control panel > search for envrionment variables
- Click on Edit environment variable
- Go to Advance tab > Select environment variable
- Create a new variable with name NPM in variable name and complete path of nodemon installation (C:\users\AppData\Roaming\npm). In my case it is C:\users\Devender\AppData\Roaming\npm as shown in the image.
- Add npm variable to Path variables
- Close command prompt and re-open
- Type nodemon –version command. It should show your the nodemon version
Solution-4 Unknown Bug or strange reasons due to that nodemon stopped working
Sometimes just reinstalling nodemon or reopening the terminal/command prompt works well to get rid of the “nodemon command not found error“. It’s strange but true.
Run the following commands to uninstall and install nodemon again.
# Remove nodemon first in Ubuntu $ sudo npm uninstall -g nodemon # In windows c:\> npm uninstall -g nodemon
# Then install nodemon $ sudo npm install -g --force nodemon or c:\> npm install -g --force nodemon
Solution-5 Package.Json file is not updated correctly
In the case of nodemon installed locally or getting the below-mentioned error while trying to start the server
[nodemon] Failed to parse config /home/dev/package.json SyntaxError: Unexpected token # in JSON at position 22 at JSON.parse () at /usr/local/lib/node_modules/nodemon/lib/config/load.js:208:23 at FSReqCallback.readFileAfterClose as oncomplete ┌───────────────────────────────────────────────────┐ │ nodemon update check failed │ │ Try running with sudo or get access │ │ to the local update config store via │ │ sudo chown -R $USER:$(id -gn $USER) /root/.config │ └───────────────────────────────────────────────────┘ npm ERR! code 1 npm ERR! path /home/dev npm ERR! command failed npm ERR! command sh -c nodemon "server" npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2021-12-05T07_17_53_247Z-debug.log
Then make sure you have “server” dependencies updated in given package.json entries.
For example, to run server.js, I have the below-mentioned entries in the package.json file by default.
{ "dependencies": { "server": "^1.0.37" } }
Replace version “1.0.37” with your “server.js” version installed on your system, in case you don’t find this entry in the package.json file.
Then run
$ npx nodemon server
- In case, you want to run your own app.js file, You can define the start property of a package’s script object. Read more on npm start scripts.
{ "scripts": { "start": "node app.js" } }
Then run the npm start command
$ npm start > npm@x.x.x start > node app.js (app.js output would be here)
In a few exceptional cases, you can also try the following steps to run server.js or your own scripts.
- By providing complete path of nodemon installation directory in package.json file, in case you are not using npx.
"scripts": { "start": "./node_modules/.bin/nodemon server.js" }
2. Sometimes issues got solved by giving node instead of nodemon in package.json file in case of legacy npm versions. For me, both node and nodemon works in scripts.
"scripts": { "start": "node index.js" }
Then run server
$ sudo npm start or c:\> npm start
- Please make a note, If the
"scripts"
the object does not define a"start"
property, npm will runnode server.js
by default.
End note
I hope you will find this article helpful. Most of the issues of nodemon command not found error get solved by just installing nodemon package globally. So I recommend you to run that first and then look for other solutions.
Let me know, which solution fixed your issue? via your comments.
Happy Learning!!