Nodejs Learn A

Source: Internet
Author: User

Node features

1. Asynchronous I/O

2. Events, callback functions

3. Single Thread

The transformation of programming ideas:

1. Synchronous programming-------> Asynchronous Programming

2. Single Thread programming

Node Application Scenario

Technology selection is extremely important to select the right technology for different scenarios

1.I/O Intensive

Node takes advantage of the processing power of the event loop instead of starting each thread for each request service

2.cpu Intensive

    

Module mechanism

COMMONJS specification

Introduction of modules, export, identifiers

Require,module,exports

The process of module loading:

Path parsing, locating files, compiling, etc.

Node module types

1.Node Core Modules

2. Third-party file modules

In a third-party module, the modules are hashed around each other and cannot be directly referenced

In addition to modules, packages and NPM are a mechanism for connecting modules

Specification for CommonJS Packages

Package is to further organize JavaScript code on a module basis

COMMONJS package specification is theory, NPM is the practice

NPM helps third-party modules complete publishing, installation, dependencies, etc.

A good ecosystem is formed between Npm,node and third-party modules.

NPM Common Commands

If you upload your personal package to the NPM repository server, you need to register your account with NPM to create a warehouse

asynchronous I/O

Why does node want to use asynchronous I/O?

1. User Experience

JavaScript and UI rendering in the front-end in the same process, in the case of synchronization, poor response

asynchronous I/O can eliminate front-end UI blocking

2. Resource allocation

Single thread Disadvantage: easy to block I/O, no multi-core CPU resources available

Multithreading disadvantage: Easy to cause deadlock, state synchronization

Node gives the intermediate scenario:

Use single thread, away from multi-threaded deadlock, state synchronization

Leverage asynchronous I/O, away from single-threaded blocking for better CPU utilization

Provides sub-threads like front-end web workers for efficient use of multicore CPUs

Node's asynchronous I/O

Complete the entire asynchronous I/O Link: event loop, observer, request object

Node Asynchronous programming

  

        

Nodejs Learn A

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.