"Nodejs" Study notes

Source: Internet
Author: User

Learning Links: http://www.cnblogs.com/zhongweiv/p/nodejs_environment.html

(a) Introduction and environmental installation

node. JS is a platform that lets JavaScript out of the browser running on the server, not the language ;

The JavaScript engine used by node. JS is a V8 from Google Chrome; JavaScript compatibility issues that run outside the browser without having to worry about headaches

The use of single-threaded, asynchronous IO and event-driven design to achieve high concurrency (asynchronous events also to some extent increased the difficulty of development and debugging);

node. JS has an HTTP server built in , so it's good news for web development;

(ii) Event module

Events is the most important module of node. js, theEvents module provides only one object, events. The core of Eventemitter,eventemitter is event launch and event listener.

Most of the modules in node. js are inherited from the event module.

Unlike events on the DOM tree, there is no event bubbling, layer-wise capture, and so on.

Eventemitter supports a number of event listeners. When an event is emitted, the event listener registered to the event is called sequentially, and the event arguments are passed as a callback function parameter.

Test source and results are as follows

/*Call the events module to get events. Eventemitter Object*/varEventemitter = require (' Events ').   Eventemitter; varEE =NewEventemitter ();/*Eventemitter.on (event, listener) registers a listener parameter 1:event string for the event, event name parameter 2: callback function*/Ee.on (' Some_events ',function(foo, bar) {Console.log ("1th listener event, parameter foo=" + foo + ", bar=" +bar);}); Console.log (' First round '); Ee.emit (' Some_events ', ' Wilson ', ' Zhong '); Console.log (' Second round '); Ee.emit (' Some_events ', ' Wilson ', ' Z ');

Run results

"Nodejs" Study notes

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.