Node.js
/Intermediate
Pipe Method
Definition
A method available on all Readable streams that automatically funnels its data into a Writable stream, automatically managing data flow and backpressure.
Explain Like I'm New
Piping is literally plumbing. If you have a hose shooting water (Readable Stream) and an empty pool (Writable Stream), the `.pipe()` method connects them. It automatically makes sure the hose doesn't shoot water faster than the pool can drain. If the pool gets full, `.pipe()` automatically pauses the hose.
Real World Example
A user asks to download a massive video from your server. Instead of loading the video into RAM, you do: `fs.createReadStream('video.mp4').pipe(res)`. The file streams directly from the hard drive straight out to the user's internet connection flawlessly.
Common Use Cases
- •Streaming files to HTTP responses
- •Connecting multiple Transform streams (like reading -> zipping -> encrypting -> writing)
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- What does `.pipe()` do?
intermediate
- How does `.pipe()` handle backpressure?