NodeJS "Hot Deploy" code for dynamic debugging

Source: Internet
Author: User

Problems encountered in the development

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.

If you modify the JS file, or debug the function, or add functionality. You will need to republish the service at this point, and each modification will need to perform the following two steps:

1 control+c

2 node Server.js

Very uncomfortable! So someone has developed an auto release (hot release) tool that you only need to save after modifying the file and it will be automatically released for you, which is called hot deployment. Save as hot-deploy as some mainstream Web application server, such as Tomcat or WebSphere. The Open source hot deployment tool in two Nodejs is described below.

(1) Supervisor

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

The command-line window displays the startup success message, which opens code snooping:

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

Supervisor this gadget can solve debugging problems in development.

Home on GitHub: https://github.com/isaacs/node-supervisor

(2) Hotnode

First need to install, open nodejs Command line tool, enter sudo npm-g install Hotcode for global installation

Once the installation is successful, you can view its version number at any time and enter it at the command line: hotcode-v

Use very simple, execute command: Hotcode server.js, output information is as follows:

Each modification will have a log printed.

Home on GitHub: Https://github.com/saschagehlich/hotnode

NodeJS "Hot Deploy" code for dynamic debugging

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.