In node. js development, the Node Supervisor is used to modify the monitoring file and automatically restart the application. node. jsnode

Source: Internet
Author: User

In node. js development, the Node Supervisor is used to modify the monitoring file and automatically restart the application. node. jsnode

In the development or debugging of Node. when you modify a js application, you always need to press CTRL + C to terminate the program and restart the program, even if you modify a small parameter, and always repeat these annoying operations. Is there a way to save time when Node. js automatically restarts (or reloads files) after the file is modified? At first, I thought of using the watch module of grunt to monitor file changes. But then I checked the changes on the net. What we thought of was something someone else had already thought of and was doing well. Node Supervisor is such a Node. js module that can meet this requirement.

According to the instructions on Github, the Node Supervisor was originally used to restart the Node. js application on the server when it crashed. Of course, it can also monitor the js (or CoffeeScript) file changes of your project, and then restart to facilitate our application debugging.

Installation Method (install with global module ):

The Code is as follows:
Npm install supervisor-g

Assume that the main portal of your Node. js program is app. js, you only need to execute the following command to start monitoring file changes.

The Code is as follows:
Supervisor app. js

The Supervisor also supports multiple parameters, as shown below:

The Code is as follows:
// The folder or js file to be monitored. The default value is '.'
-W | -- watch <watchItems>

// The monitored folder or js file to be ignored
-I | -- ignore <ignoreItems>

// Time interval (period) for monitoring file changes. The default value is the built-in time of Node. js.
-P | -- poll-interval <milliseconds>

// The file extension to be monitored. The default value is 'node | js'
-E | -- extensions <extensions>

// The main application to be executed. The default value is 'node'
-X | -- exec <executable>

// Enable the debug mode (use -- debug flag to Start node)
-- Debug

// Quiet mode. DEBUG information is not displayed.
-Q | -- quiet

Example:

The Code is as follows:
Supervisor myapp. js
Supervisor-w py_scripts-e 'py'-x python myapp. py
Supervisor-w lib, server. js, config. js, server. js

Similar products that implement the same function include Run. js and Nodeman, which I have never used. However, from the document point of view, the former and the Supervisor can be used in a simple 5-minute manner, with slightly weaker functions than the Supervisor; the latter has more feature and the corresponding documents are particularly long, it may take at least half an hour to study thoroughly. Which one is selected depends on the project requirements and personal preferences.


How to deploy nodejs on heroku

Heroku is a cloud Application Deployment platform. You can deploy simple applications (including java, ruby, and node. js applications) on it ).
Here is just a test, so with the Express framework, you can deploy your own applications according to heroku's reference.
Register
First, you must register a heroku account. This is very simple, just a mailbox.
Download heroku's own command line tool Toolbelt
Here I am on the mac platform. With homebrew, you can directly install it with one click (brew install heroku). You can download the corresponding installation package from the official website on your own platform.
Log on to your computer
Open the command line, enter heroku login, and enter the account and password as prompted.
Start Application Deployment
This section describes how to deploy node. js applications. You can perform other operations on other applications by following the steps on the official website.
Deploy the node. js Application
Write Applications
Here I directly use express to generate an application
Modify the package. json File
Example:

{

"Name": "MyMobile ",

"Version": "0.0.1 ",

"Private": true,

"Scripts ":{

"Start": "node app. js ",

"Postinstall": "./node_modules/bower/bin/bower install"

},

"Dependencies ":{

"Express ":"~ 3.4.5 ",

"Jade ":"*",

"Bower ":"*"

},

"Engines ":{

"Node": "0.10.x ",

"Npm": "1.3.x"

}

}

Add a Procfile File
Note that the Procfile file should be placed in the root directory named Procfile. Simply add one web: node web. js.
Use git to create a repository
Deploy to heroku
Heroku create
Git push heroku master
Run the application
Command Line input heroku ps: scale web = 1
You can check whether the deployment is successful. Enter heroku ps in the command line. If the output is normal, the deployment is successful.
View
Enter heroku open in the command line to open the browser, which automatically displays the application you are running in the browser.
Add your own domain name
In the DNS resolution area, use CNAME to map your own domain name to the domain name assigned to you by heroku.
Here I also use bower, so a bower command is used in package. json. In this way, heroku will automatically download the corresponding library according to the dependencies in your bower. json before running. In this way, you do not need to add these libraries to the repository to reduce the project volume.
Link to the original article:... the remaining full text>

What can nodejs do?

Node. js is a development platform running in the chromeJavascript Runtime Environment (also known as GoogleV8 engine). It is used to quickly and conveniently create server network applications. You can understand it as a lightweight JSP or PHP environment, but it is sometimes much easier to develop Web applications.
Many people do not understand why javascript is used for server-side development. Javascript is generally regarded as a browser-side scripting language, but google redevelops it as a server-side scripting environment, and its performance claims to be faster than Python, Perl, and PHP.
The biggest advantage of node. js is that it processes concurrent access. If a web application has many access connections at the same time, it can reflect the advantages of using node. js.
Another benefit is that using javascript as the server-side scripting language can eliminate some conflicts with browser-side javascript scripts. It even gives full play to the Dynamic Programming features of javascript and establishes direct dynamic programs between the server and the browser.

In general, node. js can develop dynamic websites and WEB applications like PHP.

Related Article

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.