Skip to content
Related Articles

Related Articles

How to refresh a file in Node.js ?

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Medium
  • Last Updated : 13 Feb, 2020

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
frorever start filename.js

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!