EXPRESSJS Operating principle

Source: Internet
Author: User

is looking at the source of Expressjs, first record the operating principle, the back if it is worth recording, will continue.

Expressjs is a layer of pipeline processing mechanism encapsulated on the Nodejs TCP listener. He can put the nodejs to the entire process of receiving a request to the response, and the pipeline is made up by using the. Use (Path,fun) method section.

The EXPRESSJS runs as follows:
1. After running bin/www
2. Build the App object: the object replicates all the members in the application module, also copies the Eventemitter members, and sets some default configurations
3. Encapsulate the middleware (or, optionally, a pipe) into a Layer object through App.use () and push to the stack array of the router object that has been assigned to the properties of the App object: _router.
4. Listening to TCP ports

5. Upon receipt of the request
6. Trigger the App object's handle (Req,res,next), which invokes the handle (Req,res,done) of the _rooter property, where it iterates through the stack array and takes out the middleware execution.

Note: When developing middleware, it is important to note whether next () is called, which is equivalent to the valve in the middleware and controls whether it is necessary to continue to flow to the next section of the pipeline.

Hope for valuable advice, thanks!

EXPRESSJS Operating principle

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.