Javatpoint Logo
Javatpoint Logo

Nodemon

Nodemon

Nodemon is a popular tool that is used for the development of applications based on node.js. It simply restarts the node application whenever it observes the changes in the file present in the working directory of your project.

Additionally, nodemon does not need any specific modifications to code or the mode of development. It acts as a facilitator in the node by replacing the wrapper for it. To use nodemon, you will simply need to replace the word node on the CLI while you are about to execute your script.

Installation

To carry out the installation of Nodemon in your node.js-based project use the following steps for your reference.

Although you can clone nodemon from Git but the above is a better recommendation. The above command will install the nodemon globally into your system. Also, you can install further dependencies which are highly recommended for a smooth workflow using the below command.

Note: Remember that installing nodemon locally, would not be available in your system path rather you need to run nodemon locally by calling it from the npm script with the command npx nodemon or npm start.

Creating a Node project

To create your node project, all you need to do is to follow the below very crucial steps.

First, make a directory with the below command as shown.

After making a directory, you will need to initialize the package.json using the command.

Now, all you have to do is to install express using the below command whether you have yarn or node installed in your system.

The next step is to add some plain Javascript and to do that you need to use this Javascript to configure the express through node for making the port connected to the server so that results are displayed on the console. Use the below sample code to configure your server with a listener port.

In the above code, we have established our port to listen to port number 8080. The res and req are defined as the response and the request that would be listened through the port.

The next step is to start the server using the below command.

On starting the server, it may look something like this.

Nodemon

Now, if you change inside the server.js file, the server will automatically restart, and you can get the latest output on the browser.

If you make any changes in the server.js file, it will automatically be reflected and the server will restart and the latest output will be displayed on the browser.

Conversely, nodemon will search for files driven out by your project and will look for a primary package.json file to start the script. Also, you can either opt for launching nodemon directly for your application by writing the start script in the package.json file. The package.json file may have some dependencies as shown below.

Now, all you need to do is to hit the command as shown below.

The above command will serve the same thing as discussed.

Options with Nodemon

This option is used primarily to specify the binary executable objects with the associated files. For instance, while combining the TypeScript files, it will run binary execution methods to reflect changes in the dependencies.

This option is used to ignore files or specific patterns in your working directory.

This option is used to notify the watchable file extensions. For this, you need to specify it comma separation like --ext js, ts.

This option is used to set intervals or make delays in terms of seconds.

This option is used to objectify multiple directories associated with watch. Using this option will let you specifically watch the subdirectories or files constituting your project's data.

This option is primarily used to display the changes that have been made while starting the nodemon server.

Summary

In this article, we came across the basic tutorial for understanding nodemon and creating a project with the help of it. Nodemon is generally a tool that is used to develop node.js-based applications by restarting the server whenever the changes are made and the output is reflected on the browser in real-time. It doesn't require any mode of development or additional changes since it is just a replacement wrapper for the node. As already discussed, nodemon replaces the word node on the command line while your script is being executed on the server.


Next TopicRedis Cache





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA