devnotes.

Automatic Server Restarts with Nodemon

By default, node server.js runs your code exactly once. Change a file, and nothing happens — you have to stop the process (Ctrl + C) and run node server.js again to see your edit take effect. Multiply that by every small change you make during development, and it adds up to a genuinely annoying amount of manual restarting. Nodemon exists to remove that friction entirely.

What it does

Nodemon wraps your normal node command, watches your project's files, and automatically restarts the process the instant it detects a saved change — no manual stop-and-start required.

Installing it

Most commonly installed as a dev dependency of the project, since it's only needed while developing:

npm install nodemon --save-dev

(A global install with -g also works if you want it available across every project, but per-project is generally the safer default — see the earlier page on local vs. global installs for why.)

Using it

Instead of:

node server.js

run:

npx nodemon server.js

npx runs a locally-installed package's command without needing it installed globally. From here, every time you save a change to a watched file, nodemon automatically kills the old process and starts a fresh one — your terminal will show something like [nodemon] restarting due to changes... each time.

Wiring it into an npm script

Most projects add a shortcut in package.json so nobody has to remember the exact command:

"scripts": {
  "dev": "nodemon server.js",
  "start": "node server.js"
}

Now npm run dev gives you the auto-restarting development experience, while npm start runs the plain, one-time version — the one you'd actually want in production, where automatic restarts on file changes make no sense (production files shouldn't be changing while the server runs anyway).

A small but useful config file

For bigger projects, a nodemon.json file lets you control exactly what nodemon watches and ignores:

{
  "watch": ["src"],
  "ignore": ["src/**/*.test.js", "node_modules"],
  "ext": "js,json"
}

This restricts watching to the src folder, skips test files (which usually shouldn't trigger a restart), and only reacts to .js and .json file changes.

The practical impact

It sounds like a small convenience, but across a full day of development — dozens or hundreds of small edits — the seconds saved on each manual restart add up to real, uninterrupted momentum. It's one of those tools that, once you've used it, becomes very hard to willingly give up.

Automatic Server Restarts with Nodemon | DevNotes