When developing or debugging a Node.js application, after you modify the js file, you always have to press CTRL C to terminate the program and then restart it. Even if you modify a small parameter, you always have to Keep repeating these very annoying operations. Is there a way to automatically restart Node.js (or reload the file) after the file is modified to save time? At first I thought of using grunt's watch module to monitor file changes, but then I checked online and found that others had already thought of what we had thought of and had already done a good job. Node Supervisor is just such a Node.js module that can fulfill this need.
According to the instructions on Github, Node Supervisor was originally used to restart itself when the Node.js application on the server crashes. Of course, it can also monitor changes in the js (or CoffeeScript) files of your project and then restart it to facilitate us in debugging the application.
Installation method (install as global module):
Assuming that the main entry point of your Node.js program is app.js, you only need to execute the following command to start monitoring file changes.
Supervisor also supports a variety of parameters, listed as follows:
//Folders or js files to be ignored
-i|--ignore
//The time interval (period) for monitoring file changes, the default is the built-in time of Node.js
-p|--poll-interval
//The file extension to be monitored, the default is 'node|js'
-e|--extensions
//The main application to be executed, the default is 'node'
-x|--exec
//Enable debug mode (use --debug flag to start node)
--debug
//Quiet mode, no DEBUG information is displayed
-q|--quiet
Example:
Similar products that achieve the same function include Run.js and Nodeman, both of which I have never used. But judging from the documentation, the former, like Supervisor, is a very simple one that can be used in 5 minutes, and its functions are slightly weaker than Supervisor; the latter has more features, and the corresponding documentation is very long, and it probably requires a thorough study. At least half an hour. Which one to choose depends entirely on project needs and personal preference.