Open In App

How to refresh a file in Node.js ?

Improve
Improve
Like Article
Like
Save
Share
Report

Node.js has seen an important growth in past years and is still increasing its value in many organizations and business models. Companies like Walmart or PayPal have already started to adopt it. 

NPM, the package manager of Node.js has been already installed when you install Node.js and is ready to run on your computer. Node.js doesn’t offer you the privilege of automatic restart like other languages such as PHP or Ruby. Whenever you make changes in your source code, you need to run the code again and again by using command. 

Most of us are used to save the file in Editor and then hit [ctrl + c] (To stop application) & then restart by hitting again [UP arrow + Enter]. However rather than doing this repetitive task manually, we can certainly automate it and can make the process more easier by using some tools:

  1. nodemon
  2. node-supervisor
  3. forever

1. nodemin: Among all those tools, we would like to start with nodemon first. Basically, Nodemon is a utility that monitor for any changes in your source and automatically restart your server. 

Installation Command:

npm install nodemon -g

After installing the nodemon utility we will use the following command to run the code.

nodemon filename.js

2. node-supervisor: 

Installation Command

npm install supervisor -g

After installing the node-supervisor we will use the following command to run the code.

supervisor filename.js

3. forever: The remaining tool so called forever is a node.js package that is used to keep server alive even when it crashes or stops because of some error/exception. Forever automatically restarts it. 

Installation Command

npm install forever -g
forever start filename.js

Last Updated : 03 May, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads