node. JS Hot Deployment code to automatically restart the service after modifying the code for easy real-Time debugging

Source: Internet
Author: User

When you write a scripting language like PHP, you're used to modifying the code to open the browser to see the latest results. and node. JS will parse the script file only for the first time, and will access the memory directly, avoiding repeated loading, although this design can improve performance, but it is not conducive to debugging.

In the absence of the use of third-party tools, usually modify the JS file after the manual CTRL + C to terminate the program, and then restart the node service, this is obviously a very cumbersome thing.

So there are a lot of third-party management tools (such as: Supervisor, Hotnode, forever, PM2, etc.), when the file changes saved, it can automatically restart the node service, to help developers save a lot of tedious operation.

The following is a brief introduction to the method used

Supervisor

First you need to install supervisor with NPM (note here that supervisor must be installed to the global)

$ NPM install-g Supervisor

Linux or Mac users need to use Administrator privileges

sudo npm install-g Supervisor

After the installation is complete, you can start the service with supervisor (assuming that your node. JS Program main entrance is App.js)

$ Supervisor App.js

The command-line window displays the startup success message and starts the code listener, and when the code is modified, the running script is terminated and restarted automatically.

Ps:express 4.x move the code used to start the project to the./bin/www file, use the following command if you want to use Supervisor to start the Express project

Supervisor Bin/www

Supervisor also has a lot of powerful features, I simply introduced how to monitor file changes in the development environment, automatically restart the service to facilitate the use of debugging applications, students interested in supervisor can visit the GitHub address to learn more: https:// Github.com/isaacs/node-supervisor

node. JS Hot Deployment code to automatically restart the service after modifying the code for easy real-Time 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.