stream.destroy()
The method that closes a stream straight away, releasing its resources and optionally reporting an error.
In more detail
Afterwards the stream emits close, and error too if one was given. Custom streams can implement _destroy() to free their own resources.
Related terms
- stream.pipeline() — A Node.js function that connects streams in a chain, handles backpressure, and destroys every stream in the chain if any of them fails.
- close callbacks phase — The last phase of each event loop turn, which runs close handlers, such as a socket's close event after socket.destroy().
- teardown — Removing or releasing everything that was set up for a piece of work, from a test's open connections to a whole temporary environment, once it is no longer needed.
Taught in
- Event Loop Lifecycle: The Six Phases & libuv uv_run — Node.js Internals & Backend Services
- Close Phase & Signal Dispatch: Sockets & Teardown — Node.js Internals & Backend Services
- Stream Pipelines: pipeline, AbortSignal & Teardown — Node.js Internals & Backend Services
- Native WebSockets: Bidirectional Real-Time Streams — Node.js Internals & Backend Services