Using node Supervisor in Node.js development to implement monitoring file modification and automatically restart application

Source: Internet
Author: User
Tags time interval

When you are developing or debugging a Node.js application, when you modify the JS file, you always have to press CTRL + C to terminate the program, and then restart, even if you modify a small number of parameters, it is always repeated these very annoying operations. Is there a way to save time by automatically restarting (or reloading) the file after it has been modified node.js? At first I was thinking of using grunt Watch module to monitor file changes, but later on the Internet a check, the original we think of, others have already thought of, and has done very well. Node Supervisor is just such a node.js module that can implement this requirement.

According to the instructions on GitHub, Node supervisor was originally used to reboot the server when the Node.js application crashed. Of course it can also monitor your project's JS (or coffeescript) file changes, and then restart to facilitate our debugging applications.

Installation method (installed in global module):

The

code is as follows:


npm Install supervisor-g

Assuming that your Node.js program main entrance is App.js, you can start monitoring file changes by just executing the following command.

The

code is as follows:


Supervisor App.js

Supervisor also supports a variety of parameters, listed below:

copy code code as follows:


//To monitor the folder or JS file, default to '. '


-w|--watch <watchItems>

to ignore a monitored folder or JS file
-i|--ignore <ignoreItems>

Monitor file change time interval (cycle), default to Node.js built in time
-p|--poll-interval <milliseconds>

The file name extension to monitor, default to ' Node|js '
-e|--extensions <extensions>

The main application to execute, default to ' node '
-x|--exec <executable>

Turn on debug mode (Start node with--debug flag)
--debug

Quiet mode, do not show debug information
-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 to achieve the same function and Run.js and Nodeman, both of which I have never used. But from the document point of view, the former and supervisor are very simple 5 minutes can be used in the kind of, the function is slightly weaker than supervisor, the latter feature more, the corresponding document is particularly long, estimated to study through also have at least half an hour. Choose which one to look at project needs and personal preferences.

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.