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?