While working on any node js application we have to restart node server every time we make any changes to the code. For a developer, it affects the productivity and is also irritating for some of us.
To solve this problem we have a module in node js called Supervisor. Node's Supervisor would automatically restart application whenever any of the project files is changed or modified.
Node Supervisor will restart the application every time a .js file is changed in the folder it is watching.
We can install node's Supervisor as a global module so that it can be used for all the projects.
Let's install it by running the below command.
$ npm install supervisor -g
If it gives you a permission error, try this:
$ sudo npm install supervisor -g
Now let's assume we are in a directory named mynodeapp.Inside that directory we have a file called testnode.js with the code:
console.log("Testing for node supervisor")
Now instead of starting testnode.js with node, we'll start it will supervisor:
$ supervisor testnode.js
It will print:
Testing for node supervisor
Now make some changes in this file and check a console, you will see it will automatically reload the testnode.js file.
0 Comment(s)