node. JS Learning

Source: Internet
Author: User

All asynchronous I/O operations in node. JS will send an event to the event queue when it is finished. The event is provided by the Eventemitter object.

node. js Event Loop:

The node. JS program starts with the event loop, to the event loop, and all the logic is the callback function of the event. node. js is always in the event loop, and the program entry is the callback function for the first event in the event loop.

The event callback function may issue an I/O request or a direct emission (emit) event during execution, and then return the event sequence after execution, and the event loop checks for any unhandled events in the event queue until the end of the program.

The event loop for node. JS is implemented by the Libev library. Libev supports multiple types of events, Eg:ev_io,ev_timer,ev_signal,ev_idle ... are encapsulated in the Eventemitter package.

Modules (module and package) and packages:

A package can be understood to be a collection of functional modules implemented for publishing and maintenance.

Module: File and module is one by one corresponding, a node. js file is a module, this file may be JavaScript code, JSON or compiled c/s extension.

1. Create the module:

Exports is the interface that the module exposes, and require is used to obtain the interface of a module from the outside, that is, the exports object of the acquired module.

node. JS Learning

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.