Lesson 26 / 28

Auto-Restart with nodemon

Restart the server automatically whenever a file changes.

Installing & running

nodemon watches your files and restarts Node on every save — great during development.

npm install -D nodemon
npx nodemon server.js

Node's own --watch flag

Since Node 18, node --watch server.js does the same thing natively — no package needed for simple cases.

Quick check: What is the main benefit of nodemon (or node --watch) during development?

  • It makes the app run faster in production
  • It restarts the server automatically on file changes
  • It replaces the need for testing
Answer

It restarts the server automatically on file changes — It removes the manual stop-and-restart cycle every time you edit code.