Home > Web Front-end > JS Tutorial > Use Node Supervisor in node.js development to monitor file modifications and automatically restart the application_node.js

Use Node Supervisor in node.js development to monitor file modifications and automatically restart the application_node.js

WBOY
Release: 2016-05-16 16:31:57
Original
1458 people have browsed it

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):

Copy code The code is as follows:

npm install supervisor -g

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.

Copy code The code is as follows:

supervisor app.js

Supervisor also supports a variety of parameters, listed as follows:

Copy code The code is as follows:

//The folder or js file to be monitored, the default is '.'
-w|--watch

//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:

Copy code The code is as follows:

supervisor myapp.js
supervisor -w py_scripts -e 'py' -x python myapp.py
supervisor -w lib, server.js, config.js, server.js

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template