🕵️‍♀️Nodemon🕵️‍♀️

🕵️‍♀️Nodemon🕵️‍♀️

What is Nodemon and How to Use it with NodeJS Apps

In Node.js, whenever you make any changes in your application source code, you would have to manually restart the application process for those changes to take effect🙁.

You can eliminate this extra step by using Nodemon😃 to restart the process automatically.

On every file save and your Node.js server is automatically restarted for you as easy as that.

What is Nodemon?🙄

It’s very painful to restart the server every time when the code changes. Nodemon lets you restart the server automatically whenever the code changes. Now you don’t need to restart the server every time the code changes it will do it for you😉. Just install Nodemon and forget about it.

So how would you install it?🤔

Install Nodemon

I assume you have Node.js and NPM installed. You can install Nodemon on your machine, globally, or locally on your project using NPM.

  • Install Nodemon globally🤓

To install it globally, run "npm install --global nodemon". And Nodemon will be installed on your system path, and you will be able to use the "nodemon" 😯command directly on the command line.

  • Install Nodemon locally🤫

You can also install Nodemon locally as a development dependency by running "npm install --save-dev nodemon". With a local installation, Nodemon will not be available in your system path. And this means if you try running the "nodemon" command, you will receive “command not found”.

Instead, the local installation of Nodemon can run by calling it from within an NPM script.

  • Just run the command :
npm install nodemon -g

This will install nodemon on your computer globally as -g is provided in the command.

When you start the server rather than using this command npm start or node app.jsnow you just have to use

nodemon

or

//If your file name is app.js or whichever file name you want to use
nodemon app.js

This will start the server for you and when any code changes within the directory it will restart it automatically🤗.

Here is a screenshot:

Screenshot 2022-11-18 183505.png

Conclusion🙆‍♀️

We have seen that nodemon is a very useful tool for Node.js development. Be it a web server, a command line interface (CLI) command or any other workload nodemon will make your life a lot easier.

Nodemon is like having someone restart your servers for you on every file change. It is very handy when writing web applications because it makes testing a lot more frictionless.

I hope you have learned💁‍♀️ how to use Nodemon to automatically restart your Node.js application with this quick tutorial❤️.

Did you find this article valuable?

Support Chhakuli Zingare by becoming a sponsor. Any amount is appreciated!