In node. js development, the Node Supervisor is used to modify the monitoring file and automatically restart the application.

Source: Internet
Author: User

In node. js development, the Node Supervisor is used to modify the monitoring file and automatically restart the application.

In the development or debugging of Node. when you modify a js application, you always need to press CTRL + C to terminate the program and restart the program, even if you modify a small parameter, and always repeat these annoying operations. Is there a way to save time when Node. js automatically restarts (or reloads files) after the file is modified? At first, I thought of using the watch module of grunt to monitor file changes. But then I checked the changes on the net. What we thought of was something someone else had already thought of and was doing well. Node Supervisor is such a Node. js module that can meet this requirement.

According to the instructions on Github, the Node Supervisor was originally used to restart the Node. js application on the server when it crashed. Of course, it can also monitor the js (or CoffeeScript) file changes of your project, and then restart to facilitate our application debugging.

Installation Method (install with global module ):

 

The Code is as follows:


Npm install supervisor-g

 

Assume that the main portal of your Node. js program is app. js, you only need to execute the following command to start monitoring file changes.

 

The Code is as follows:


Supervisor app. js

 

The Supervisor also supports multiple parameters, as shown below:

 

Copy the Code as follows:


// The folder or js file to be monitored. The default value is '.'
-W | -- watch <watchItems>

 

// The monitored folder or js file to be ignored
-I | -- ignore <ignoreItems>

// Time interval (period) for monitoring file changes. The default value is the built-in time of Node. js.
-P | -- poll-interval <milliseconds>

// The file extension to be monitored. The default value is 'node | js'
-E | -- extensions <extensions>

// The main application to be executed. The default value is 'node'
-X | -- exec <executable>

// Enable the debug mode (use -- debug flag to Start node)
-- Debug

// Quiet mode. DEBUG information is not displayed.
-Q | -- quiet

 

Example:

 

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 implement the same function include Run. js and Nodeman, which I have never used. However, from the document point of view, the former and the Supervisor can be used in a simple 5-minute manner, with slightly weaker functions than the Supervisor; the latter has more feature and the corresponding documents are particularly long, it may take at least half an hour to study thoroughly. Which one is selected depends on the project requirements and personal preferences.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.