Using supervisor to improve Nodejs commissioning efficiency

Source: Internet
Author: User

If you have a PHP development experience, you will be accustomed to refresh the browser directly after modifying the PHP script to observe the results, and you
When developing an HTTP application implemented by node. JS, you will find that no matter which part of the code you modify, you must terminate
node. JS will not work until it is rerun. This is because node. js only parses the foot when it is first referenced to a part
This file will be accessed directly in the future, avoiding repeated loading, while PHP will always re-read and parse the script (e.g.
No specific optimized configuration). This design of node. JS, while improving performance, is not conducive to the development of debugging, because
Instead of terminating the process and restarting it every time, we always want to see the effect as soon as we are in the process of development.
Supervisor can help you implement this feature by monitoring your code changes and automatically restarting node. js.
The easy way to use it is to first use NPM to install Supervisor:
$ NPM install-g Supervisor

If you are using Linux or Mac, typing the above command directly is likely to have a permissions error. The reason is NPM
You need to install Supervisor to the system directory and require administrator authorization to use sudo npm install-g
Supervisor command to install.
Next, start app.js with the Supervisor command:

$ supervisor App.js debug:running node  with  ' app.js '--watch '. '  --extensions ' node|js '--exec ' node ' with ' node App.js '/home/byvoid/. '  3000.

When the code is changed, the script that is run is terminated and then restarted. The results shown in the terminal are as follows:

 with ' Node App.js '. Supervisor This gadget can solve debugging problems in development. 

3.2 Asynchronous I/O and event programming

The installation of the supervisor is also simple:

Install directly with NPM you can type the command: Npm-g Install Supervisor

Note here that supervisor must be installed to the global, if you do not install to the global, the error command will prompt you to install to the global.

If you do not want to install to the default global, you can modify the global path to the current path yourself

NPM config set prefix "path"

After installation, you can use supervisor to start the service.

Supervisor App.js

The boot is exactly like this.

Modify, and then refresh


If you think this article is helpful to you, please click "Recommend", would you like to make progress with me? Then "pay attention" to me!

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.