Restart Node Application Automatically

Nodemon is a utility that will monitor for any changes in your source and automatically restart your server. Perfect for development.

Just use nodemon instead of node to run your code, and now your process will automatically restart when your code changes. To install, get node.js, then from your terminal run:

npm install -g nodemon

If you’re using yarn as a package manager

yarn global add nodemon

So run your app using nodemon nodemon <YOUR_APP_FILE>.js

Arguments can be passed-in the same way as if you were running the script with Node:

nodemon server.js 3006

As you can see from the screenshot above, the terminal output from your Node.js app is displayed normally. You can restart the process at any time by typing rs and hitting enter.

  • Automatic restarting of application.
  • Detects default file extension to monitor.
  • Default support for node & coffeescript, but easy to run any executable (such as python, make, etc).
  • Ignoring specific files or directories.
  • Watch specific directories.
  • Works with server applications or one time run utilities and REPLs.
  • Requirable in node apps.
  • Open source and available on github.

Chamod Shehanka a FullStack Developer at Platformer and Writer at Noteworthy, Platformer and The Java Report