. Advertisement .
..3..
. Advertisement .
..4..
Developers are aware the Node.js and have worked on it. Nodemon is an amazing utility for Node.js as it let you focus on the code writing without even worrying to refresh in the middle to see the changes. With the Nodemon, you just need to restart the app to check the directories or files at any time when modified. When working with the node.js, you may encounter the nodemon: command not found error, especially when you are just starting to use it.
Beginners often get this error warning, when they try to install nodemon. For installing, you would be needing npm and node.js. Let’s shed light on how to fix nodemon: command not found error.
How to fix nodemon: command not found error
To fix the error, you need the installation as we have discussed above. The error can be solved by using the ‘npx
’ or installing the package globally with ‘npm install-g nodemon
’. Check out ways to fix the error
Using the ‘npx’ Command
This command is the simplest yet fastest way to fix the error
npx nodemon@latest server.js
npx nodemon@latest –version
Install Nodemon Globally
If you don’t have the nodemon installed globally, you may experience the command error. Installing the package globally can fix this error. With this, you can also have control over the package’s version in the ‘package.json’ file.
# installs nodemon globally (can run from any directory)
npm install -g nodemon
# (better) installs nodemon locally to the project (must be ran from root directory)
npm install --save-dev nodemon
To create a command in the ‘script
’ object of the ‘package.json
’ file, you can use the following code
{
"scripts": {
"dev": "nodemon server.js"
}
}
As you ran ‘npn install –save-dec nodemon’, from the directory ‘node_modules’, this resolves the error.
Check User Access
When installing nodemon, you need to make sure you have permission or user access. If you don’t have the proper access, you will encounter theerror when you try to run your project. Use this to install the nodemon globally with sufficient access
$ sudo su
$ npm install -g nodemon
# OR
$ sudo npm install -g nodemon
In the case, you don’t see an option to install using root access or sudo, then you should at least have access to the npm directory. To get the ownership access to the npm directory, this command can help
$ sudo chown -R yourUsername /usr/local/lib/node_modules
$ sudo chown -R yourUsername /usr/local/bin/
$ sudo chown -R yourUsername /usr/local/share/
After this, you can install with access of your own without needing to have sudo or root access
$ npm install -g nodemon
Check if Nodemon Stopped Working
Sometimes, the error occurs when the nodemon stopped working. If it happens, reinstalling works. First, you need to uninstall and then install using the code
To uninstall, you can run the command
c:\> npm uninstall -g nodemon
then, to install, you can use
c:\> npm install -g --force nodemon
Conclusion
We have discussed the ways you can solve the nodemon: command not found error. With the commands, you can get through the error. Hope you find it useful!
Leave a comment