NodeJs - How to Configure Nodemon to Auto-reload NodeJs App


➤ Introduction To Nodemon.

The nodemon is an npm module developed by @remy. The nodemon is used with Node.js applications and helps in automatically restarting the node.js application when any change is made in the project files. Nodemon is super easy to use and doesn’t require any tedious configuration. This module is downloaded around 1, 547, 346 times weekly, it comes under MIT license and can be used by anybody

When you make changed any product directory file then server will automatically restart. you don't want restart app manual.

➤ How To Installed Nodemon?

First, you need to install NodeJs.

After installing NodeJs you need to open Command Prompt.

⇒ You need to write following command :

> npm install -g nodemon
After installed nodemon, We make one simple example for you so you can better understand.

➤ Example For Nodemon :

● First you need to create a App folder, here we are using E:\> drive

E:\> mkdir example-app

● After hit mkdir command you will get example-app folder in E: drive. then go to inside example-app directory using following command.

E:\> cd example-app

After enter this command you will go inside example-app directory.

Now, we need to create package.json file using initilize npm command.

Following command is used to initilize package.json file on root directory.

> npm init -y

After run this command you will get package.json file inside example-app on root place, when you will open it you will get a json like this.

{
  "name": "example-app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

After creating package.js file we need to create one index.js for run application.

Now, we need to install nodejs webframework express using npm, write following commnand for install express.

> npm install express

Then open index.js any text editor and write following code for initilize express.

var express = require("express");
var app = express();


app.listen(1200,function(){
	console.log("Running Server On.");
	console.log("Here Name");
	
});

run you application using following command.

> nodemon index.js

We are listen port 1200,you can run application on localhost:1200 port

When i change string "Here Name is code4js" and save file then automatically server will restart

Comments