TIL: Auto-Restarting Node.js Processes With nodemon
Restarting Node.js manually after every edit is a cycle that breaks focus. nodemon watches files and restarts automatically.
npm install -g nodemon
nodemon server.js
Every time server.js or any imported module changes, nodemon kills the process and restarts it. The terminal shows the restart happening with a clear message.
nodemon --ext js,json server.js
Watch .js and .json files. By default nodemon watches .js, .mjs, .json. Specify the extensions explicitly to include or exclude types.
nodemon --ignore tests/ server.js
Ignore the tests directory. Running the full test suite triggers restarts that you do not need while developing the server code.
Does nodemon work with TypeScript?
nodemon --exec ts-node server.ts
The –exec flag replaces the default node command. Run ts-node or tsx through nodemon to restart on TypeScript file changes.
How do I stop nodemon?
Ctrl+C stops the process. nodemon exits cleanly and the child process is terminated.