When you write a scripting language like PHP, you're used to modifying the code to open the browser to see the latest results. and node. JS will parse the script file only for the first time, and will access the memory directly, avoiding repeated loading, although this design can improve performance, but it is not conducive to debugging.
In the absence of the use of third-party tools, usually modify the JS file after the manual CTRL + C to terminate the program, and then restart the node service, this is obviously a very cumbersome thing.
So there are a lot of third-party management tools (such as: Supervisor, Hotnode, forever, PM2, etc.), when the file changes saved, it can automatically restart the node service, to help developers save a lot of tedious operation.
The following is a brief introduction to the method used
Supervisor
First you need to install supervisor with NPM (note here that supervisor must be installed to the global)
$ NPM install-g Supervisor
Linux or Mac users need to use Administrator privileges
sudo npm install-g Supervisor
After the installation is complete, you can start the service with supervisor (assuming that your node. JS Program main entrance is App.js)
$ Supervisor App.js
The command-line window displays the startup success message and starts the code listener, and when the code is modified, the running script is terminated and restarted automatically.
Ps:express 4.x move the code used to start the project to the./bin/www file, use the following command if you want to use Supervisor to start the Express project
Supervisor Bin/www
Supervisor also has a lot of powerful features, I simply introduced how to monitor file changes in the development environment, automatically restart the service to facilitate the use of debugging applications, students interested in supervisor can visit the GitHub address to learn more: https:// Github.com/isaacs/node-supervisor
node. JS Hot Deployment code to automatically restart the service after modifying the code for easy real-Time debugging