Node.js v18.12.1 documentation


Table of contents

Stream[src]#

Stability: 2 - Stable

Source Code: lib/stream.js

A stream is an abstract interface for working with streaming data in Node.js. 流是用于在Node.js中处理流数据的抽象接口。The node:stream module provides an API for implementing the stream interface.node:stream模块提供了用于实现流接口的API。

There are many stream objects provided by Node.js. Node.js提供了许多流对象。For instance, a request to an HTTP server and process.stdout are both stream instances.例如,对HTTP服务器的请求process.stdout都是流实例。

Streams can be readable, writable, or both. 流可以是可读的,也可以是可写的,或者两者兼而有之。All streams are instances of EventEmitter.所有流都是EventEmitter的实例。

To access the node:stream module:要访问node:stream模块:

const stream = require('node:stream');

The node:stream module is useful for creating new types of stream instances. node:stream模块用于创建新类型的流实例。It is usually not necessary to use the node:stream module to consume streams.通常不需要使用node:stream模块来使用流。