Wednesday, February 21, 2024
ExplainerProgrammingTech/Web

Nodemon – Automatic Restart the node application

What is Nodemon ?

Nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected.

nodemon does not require any additional changes to your code or method of development. nodemon is a replacement wrapper for node, to use nodemon replace the word node on the command line when executing your script.


ExpressJS – Web framework for Node.js

 

How To Install Node.js on Ubuntu

 

 


Features

  • 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.

Nodemon Installation

Either through cloning with git or by using npm (the recommended way):

npm install -g nodemon

Now will be installed globally to your system path.

You can also install as a development dependency:

npm install --save-dev nodemon

With a local installation, nodemontool will not be available in your system path. Instead, the local installation of nodemon can be run by calling it from within an npm script (such as npm start) or using npx nodemon.

Usage

nodemontool wraps your application, so you can pass all the arguments you would normally pass to your app:

nodemon [your node app]

For CLI options, use the -h (or --help) argument:

nodemon -h

Using this tool is simple, if my application accepted a host and port as the arguments, I would start it as so:

nodemon ./server.js localhost 8080

Any output from this script is prefixed with [nodemon], otherwise all output from your application, errors included, will be echoed out as expected.

If no script is given, nodemon will test for a package.json file and if found, will run the file associated with the main property (ref).

You can also pass the inspect flag to node through the command line as you would normally:

nodemon --inspect ./server.js 80

If you have a package.json file for your app, you can omit the main script entirely and it will read the package.json for the main property and use that value as the app.

nodemon will also search for the scripts.start property in package.json (as of nodemon 1.1.x).

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

2 thoughts on “Nodemon – Automatic Restart the node application

Leave a Reply

Your email address will not be published. Required fields are marked *