Last modified: Jul 16, 2025 By Alexander Williams
How to Install Nodemon in Node.js
Nodemon is a useful tool for Node.js developers. It automatically restarts your server when files change. This saves time during development.
What is Nodemon?
Nodemon is a utility module for Node.js. It monitors your project files. When changes are detected, it restarts your Node.js application automatically.
This eliminates the need to manually stop and restart your server. It's perfect for development environments. Learn more about Express module for building servers.
Prerequisites
Before installing nodemon, you need:
- Node.js installed on your system
- npm (comes with Node.js)
- A basic Node.js project
Installing Nodemon Globally
The easiest way to use nodemon is to install it globally. This makes it available for all projects.
npm install -g nodemon
+ nodemon@3.0.2
added 1 package in 2.3s
The -g
flag installs nodemon globally. You can now use it in any project.
Installing Nodemon as a Dev Dependency
For project-specific use, install nodemon as a dev dependency. This is better for team projects.
npm install --save-dev nodemon
The --save-dev
flag adds it to devDependencies in package.json. Similar to how you'd install dotenv for environment variables.
Using Nodemon
After installation, use nodemon instead of node to run your application.
nodemon app.js
[nodemon] 3.0.2
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node app.js`
Server running on port 3000
Nodemon will now watch your files. It restarts the server when changes occur.
Configuring Nodemon
You can configure nodemon through a nodemon.json file. This lets you specify watch options.
{
"watch": ["src"],
"ignore": ["src/tests"],
"exec": "node app.js"
}
This configuration watches only the src folder. It ignores test files. Similar to configuring Mongoose for MongoDB.
Common Issues
If nodemon doesn't work, check these solutions:
- Verify global installation with
nodemon -v
- Check for permission issues on Linux/macOS
- Ensure your package.json has the correct scripts
For module errors, see our guide on fixing missing modules.
Conclusion
Nodemon is essential for Node.js development. It improves workflow by automatically restarting your server. Install it globally or per project as needed.
Remember to configure it properly for complex projects. Happy coding with your new automated workflow!