A Node. Js

  1. Node.js is a platform

(1) It combines multiple technologies. (2) Let JavaScript also call the system interface, the development of back-end applications.

  1. What applications are used in Node.js?

(1) V8 engine (2) Libuv (3) C/C++ implementation of C_ares (DNS resolution), HTTP_server (HTTP resolution),openSSL (encryption and decryption), Zlib (compression) and other libraries

  1. Node.js workflow

Two Node.js technology architecture

  1. The top layer is the Node.js API, including HTTP, FS, STREAM and other modules.
  2. The second layer contains Node.js Bindings (enabling JS to communicate with C/C ++) and C/C ++ plugins (customizable other functions).
  3. The bottom tier includes the V8 engine, cross-platform asynchronous I/O capabilities, DNS resolution, encryption and decryption, and more

What is Bindings?

  1. Js is a bridge to the c++ library, extending the capabilities of js
  2. Node.js wraps http_parser in C++ to make it conform to certain requirements. The file is called http_parser_bindings. CPP. Compile it into a usable file using the compilation tools provided by Node.js. Js code can require the available file directly. In this way, js can call the c++ library, and the intermediate bridge is binding. Since Node.js provides a lot of binding, add an S. This is Bindings.
  3. Js and c++ interaction, official website document example

What is libuv?

A cross-platform asynchronous I/O library that can be used for TCP, UDP, DNS, file and other asynchronous operations. With this capability, Node.js can get rid of the I/O bottleneck, leaving all the I/O work to C/C ++ and only making simple calls.

Five what is V8?

  1. function

(1) Turn js source code into native code and execute it. (2) Maintain the call stack to ensure the execution sequence of JS functions. (3) Memory management, allocating memory for all objects. (4) Garbage collection, reuse of useless memory. (5) Implement JS standard library.

  1. Pay attention to

(1) V8 does not provide DOMAPI, DOMAPI browser does. (2) V8 executes JS in a single thread. (3) Two threads can be opened to execute JS respectively. (4) V8 itself contains multiple threads, such as garbage collection as a single thread. (5) It has its own Event loop, but Node.js makes one based on Libuv.

What is event Loop?

  1. The operating system can fire events, and JS can handle them. But the events that are fired are sequential, and even if they are fired at the same time, they are executed in sequential order. The Event loop manages the order in which events are processed.
  2. Sequence diagram

  1. The key stage

(1) Timer Checks the timer. (2) poll Polls to check system events. (3) Check setImmediate callback. (4) Less used in other stages.

  1. Pay attention to

Most of the time, Node.js is parked in the poll polling phase. Most events are processed in the poll phase, such as files and network requests.

Seven summarizes

Node.js

  1. Asynchronous I/O operations with Libuv.
  2. Use event loop to manage the order of event processing.
  3. Efficient DNS/HTTP handling with C/C ++ libraries.
  4. Bindings can be used to enable JS and C/C ++ communication.
  5. Run JS with V8.
  6. Simplify JS code with the Node.js standard library.

Simply put, Node.js is a platform that makes the JS code running on it more powerful.