Getting to know node.js


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


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


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


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


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.


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


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


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


Use the underlying operating system facilities to perform name resolution


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


For error handling


Node.js event API

File System

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


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


The node.js HTTP interface supports many traditional protocols


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


Simple module loading system of node.js


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


The OS module provides some operating system related methods


Provide file or path processing methods


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()


Will be discarded and not recommended

Query Strings

Provides an API for formatting and parsing URL strings


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


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 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




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


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


The Dgram module provides the implementation of UDP datagram socket


Provides an API for URL processing


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


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


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


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