node. JS uses supervisor encounters ' supervisor ' not internal or external commands, if resolved?

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 when you develop the node. JS implementation of the HTTP application, you will find that no matter which part of the code you modify, you must terminate node. js and re-run it to be effective. This is because node. js only parses the script file the first time it is referenced to a part, and then accesses the memory directly, avoiding repeated loading, while PHP always re-reads and parses the script (if there is no specific optimization configuration). This design of node. JS, while improving performance, is not conducive to development debugging because we always want to see the effect as soon as we change it, rather than terminating the process and restarting it every time.

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 that NPM needs to install supervisor to the system directory, which requires administrator authorization and can be installed using the sudo npm install-g Supervisor command.

Next, start app.js with the Supervisor command: $ supervisor App.js

DEBUG: Running node-supervisor withDEBUG:   program ‘app.js‘DEBUG:  --watch ‘.‘DEBUG:  --extensions ‘node|js‘DEBUG:  --exec ‘node‘DEBUG: Starting child process with ‘node app.js‘DEBUG: Watching directory ‘/home/byvoid/.‘ for changes. HTTP server is listening at port 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:

DEBUG: crashing childDEBUG: Starting child process with ‘node app.js‘HTTP server is listening at port 3000.

Supervisor this gadget can solve debugging problems in development.

node. JS uses supervisor encounters ' supervisor ' not internal or external commands, if resolved?

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.