---
title: "How do I restart my Node.js app when files change without nodemon?"
description: "Node.js has a built-in watch mode that restarts your app when files change. Learn how node --watch works, what it watches, and when you still need another tool."
url: https://www.danny.engineering/answer/nodejs/how-do-i-restart-my-nodejs-app-when-files-change-without-nodemon
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T18:57:00.000Z
tags: ["Node.js"]
---

# How do I restart my Node.js app when files change without nodemon?

## The short answer


Run your entry file with `node --watch`. Node.js restarts the process whenever that file or any module it imports changes. Watch mode has been stable since Node.js 22.0.0, so on any current release you can drop nodemon for most projects.


```json
{
  "scripts": {
    "dev": "node --watch src/server.js"
  }
}
```


## Why it happens


Node.js loads your code into memory once when the process starts. Editing a file on disk does not change the code that is already running, so without a watcher you have to stop and start the process by hand.


nodemon solved this by watching your folders and restarting Node.js for you. Watch mode builds the same idea into Node.js itself: it tracks the files your app actually loads through `import` and `require`, and when one changes it stops the process and starts a fresh one.


## How to fix it


### Use --watch for the entry file and its imports


This is all most servers need. Only files that are part of the module graph trigger a restart, so editing a README or a test file does not restart your server.


```bash
node --watch src/server.js
```


Node.js options go before the file name. Anything after the file name is passed to your script as an argument.


### Use --watch-path for files you read yourself


Files you read with `fs` at runtime, such as templates, JSON config read with `readFile`, or SQL files, are not imports, so `--watch` does not see them. Point watch mode at folders explicitly with `--watch-path`. You can repeat the flag. Note that using `--watch-path` turns off the automatic watching of imported modules, so include your source folder too.


```bash
node --watch-path=./src --watch-path=./templates src/server.js
```


Check the `--watch-path` section of the CLI docs for your Node.js version, as its stability level and platform notes differ from plain `--watch`.


### Keep your terminal output between restarts


Watch mode clears the console on each restart. Add `--watch-preserve-output` if you want to scroll back through earlier logs.


```bash
node --watch --watch-preserve-output src/server.js
```


### Combine it with other built-in features


Watch mode works alongside other flags, so a typical dev script can load environment variables and restart on change with no extra packages.


```json
{
  "scripts": {
    "dev": "node --watch --env-file=.env src/server.js",
    "test:watch": "node --test --watch"
  }
}
```


### Shut down cleanly on restart


On each restart Node.js signals the old process to stop. If you hold resources such as a database pool or an open port, listen for the signal and close them, so the new process does not hit `EADDRINUSE`.


```javascript
process.on('SIGTERM', async () => {
  await pool.end();
  server.close(() => process.exit(0));
});
```


### When you still need another tool


nodemon or a similar watcher is still useful if you need to run a command that is not Node.js, add a delay before restarting, or run custom actions on change. Bundler-based frameworks such as Next.js or Vite have their own dev servers with hot reload, so use those rather than watch mode.


## Common pitfalls

- Putting `--watch` after the file name, where it becomes an argument to your script.
- Expecting changes to `.env` or files read with `fs` to trigger a restart without `--watch-path`.
- Using watch mode in production. It is a development tool; use a process manager or your platform's restart policy instead.
- Leaving long-running timers or open handles that delay the old process exiting, which makes restarts feel slow.

## Related reading

- [Node.js CLI: --watch](https://nodejs.org/api/cli.html#--watch)
- [Node.js CLI: --watch-path](https://nodejs.org/api/cli.html#--watch-path)
