Getting to know node.js

Time:2021-9-15

Node.js introduction

Node definition

Node.js is a JavaScript runtime environment built on the chrome V8 engine

Node features

  • Asynchronous event driven

Getting to know node.js

Node.js uses the callback function to handle blocking events. Node.js maintains a thread pool. When a blocking event is encountered, it takes a thread from the thread pool to execute the blocking event, then executes the callback function, and the thread returns to the thread pool.

  • non-blocking io

  • Single thread

  • You can use child_ The process. Fork (modulepath, args) API implements multiple threads

  • HTTP is a first-class citizen in node.js, which is very suitable for web applications

Node architecture

Getting to know node.js

V8

Google’s open source high-performance JavaScript engine is used to interpret and execute JavaScript

libuv

High performance event driver library encapsulates some underlying platform features of windows and UNIX

C / C + + Component Library (c-ares HTTP parser open SSL zlib, etc.)

It provides the function of accessing the bottom layer of the system

Node.js API

Node.js provides the API used

Node.js Bindings

Glue code to expose the C / C + + class library interface to JavaScript

C/C++ Addons

Dynamically linked objects are used to provide interfaces between node.js, JavaScript and C / C + +

Node installation directory structure under Windows

Node installation directory

Getting to know node.js

NPM modules directory

Getting to know node.js

Node API overview (v6.10.2)

Assertion Testing

Assertion test

Buffer

Operation binary stream

C/C++ Addons

Dynamically linked objects are used to provide interfaces between node.js, JavaScript and C / C + +

Child Processes

child_ The process module provides the ability to generate child processes in a similar but not exactly the same way as Popen (3). This function is mainly provided by child_ The process. Spawn() function provides

Cluster

A single instance of node.js runs in a single thread. In order to take advantage of multi-core systems, users sometimes want to start a cluster of node.js processes to handle the load.
The cluster module allows you to easily create child processes for all shared server ports

Command Line Options

Node.js comes with various cli options. These options expose built-in debugging, multiple ways to execute scripts, and other useful runtime options.

Console

The console module provides a simple debugging console, which is similar to the JavaScript console mechanism provided by the web browser

Crypto

The encryption module provides encryption functions, including a set of wrappers for OpenSSL hash, HMAC, encryption, decryption, signature and verification functions.

Debugger

Node.js includes out of process debugging utilities that can be accessed through TCP protocol based and built-in debugging clients. To use it, start node.js with debugging parameters, followed by the path of the script for debugging; A prompt is displayed indicating that the debugger started successfully

DNS

Use the underlying operating system facilities to perform name resolution

Domain

The module will be discarded. Once the replacement API has been completed, the module will be completely discarded.

Errors

For error handling

Events

Node.js event API

File System

File I / OAPI, provided by a simple wrapper over standard POSIX functionality

Globals

All modules provide these objects. Some of these objects are not actually in the global scope, but in the module scope

HTTP

The node.js HTTP interface supports many traditional protocols

HTTPS

HTTPS is an HTTP protocol over TLS / SSL. A separate module is used in node.js to implement the protocol

Modules

Simple module loading system of node.js

Net

Asynchronous network wrapper is used to realize the function of network communication between server and client

OS

The OS module provides some operating system related methods

Path

Provide file or path processing methods

Process

It provides APIs such as process processing and process information acquisition of node.js. Process is global and does not need to be loaded with require()

Punycode

Will be discarded and not recommended

Query Strings

Provides an API for formatting and parsing URL strings

Readline

The readLine module provides an interface to read data from a readable stream

REPL

The repl module provides a read Eval print loop (repl) implementation, which can be used as a stand-alone program or included in other applications

Stream

Stream module is used to implement the abstract interface of data stream processing. It provides an API that can easily build stream processing objects

String Decoder

Provides an API to encode buffer objects into strings

Timers

timer

TLS/SSL

TLS module provides transport layer security protocol (TLS) and secure socket layer protocol (SSL) built on OpenSSL

TTY

The TTY module provides TTY. Readstream and TTY. Writestream classes

UDP/Datagram

The Dgram module provides the implementation of UDP datagram socket

URL

Provides an API for URL processing

Utilities

It mainly provides the basic methods used by internal programs, but it can also be accessed externally

V8

The V8 module exposes an API specific to the V8 version built into the node.js binary

VM

The VM module provides APIs for compiling and running code in the context of a V8 virtual machine

ZLIB

The zlib module provides compression functions in the form of gzip and deflate / inflate