If you’re developing with Node.js, you’ve probably had to restart your server manually every time you make a change. It gets frustrating fast—especially when you’re testing new features or fixing bugs—but Nodemon makes your life easier.
With Nodemon, your server automatically restarts whenever you modify a file, eliminating the need for manual resets. In this guide, we’ll install Nodemon, configure it for your development workflow, and ensure it runs seamlessly with your Node.js project.
What is Nodemon?
Nodemon is a command-line utility that watches your file system for changes in the directory where it’s running. Whenever a file is modified, Nodemon automatically restarts your application, whether it’s a long-running process like a web server or a one-time script that exits cleanly. This makes development much faster and more efficient, eliminating the need to manually stop and restart your server.
Using Nodemon is simple—just replace node
with nodemon
when running your code, and your application will restart automatically whenever changes are detected. Nodemon requires no modifications to your existing code. While it’s designed for Node.js, it’s flexible enough to work with other languages like Python, Ruby, or any process that runs in a terminal.
How to Install Nodemon
To install Nodemon, you need to have Node.js and NPM installed. You can install it globally (to use anywhere) or locally (within a specific project).
How to Install Nodemon Globally
If you want to use Nodemon across multiple projects without reinstalling, install it globally with:
npm install -g nodemon
This adds Nodemon to your system path, allowing you to run nodemon
from the command line.
Check if Nodemon is installed by running:
nodemon -v
If a version number appears, the installation was successful. If not, try reinstalling Nodemon globally.
How to Install Nodemon as a Dev Dependency
Prefer keeping dependencies isolated within your project? Install it locally as a dev dependency.
Navigate to your project folder or initialize a new one using:
npm init -y
Then install Nodemon running:
npm install --save-dev nodemon
Local installation means Nodemon isn’t added to your system path. If you try running nodemon
globally, you might see “nodemon command not found.
To verify it’s installed locally run:
npm list --depth=0 | findstr nodemon # Windows
npm list --depth=0 | grep nodemon # Mac/Linux
How to Use Nodemon to Run a Node.js Server
Now let’s see Nodemon in action. Here’s a simple Node.js server:
const http = require("http");
const host = process.argv[2] || 'localhost';
const port = process.argv[3] || 3000;
const server = http.createServer((req, res) => {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("Hello, Nodemon!");
});
server.listen(port, host, () => {
console.log(`Server running at ${host}:${port}`);
});
This starts a basic server at localhost:3000.
npx nodemon server.js
Or if Nodemon is installed globally:
nodemon server.js
Now, every time you save changes to your files, Nodemon will automatically restart the server for you.
Modify “Hello, Nodemon!” in the code, save the file, and watch as Nodemon reloads instantly. Now, if you refresh the browser, you’ll see your changes reflected.
You can pass arguments to your script exactly the same way you would with plain Node.js. For example:
npx nodemon server.js localhost 8080
Nodemon itself does not process these arguments—it forwards them to your Node.js script. Inside your code, you can access them using process.argv
, which is an array of command-line arguments passed to the script.
This is especially helpful when you want to customize ports or environments dynamically.
💡If you ever need to restart the server manually, simply type
rs
and press Enter in the terminal where Nodemon is running.
How to Add Nodemon to package.json
Instead of manually typing nodemon server.js
, let’s add a script to package.json
that runs Nodemon for us. We’ll name it dev
, but you can choose any name you like.
"scripts": {
"dev": "nodemon server.js"
}
This makes running your dev server as easy as typing
npm run dev
💡 This works regardless of whether Nodemon is installed globally or as dev dependency—npm handles the path automatically.
GitHub Repo
Want to test this out quickly? We’ve created a sample repo with everything in place.
👉 Clone the repo, install dependencies, and try running Nodemon on your machine right away.
Wrap-Up
That’s it! Now you know how to install Nodemon globally and locally, run your Node.js server with Nodemon, pass custom arguments for flexibility and add Nodemon to package.json
for easier execution
Why is this important? Because every second counts in development. Manual restarts may seem small, but they add up fast. Using Nodemon streamlines your workflow and lets you focus on writing code, not restarting servers.
🧠 Explore more Nodemon guides and examples.
Try out Nodemon in your next project and see the difference in your development workflow.
If this guide helped you, consider sharing it, and feel free to leave a comment with questions or feedback.
Happy coding!