Skip to content
how to write node programs with streams
JavaScript HTML CSS Shell
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
readme.markdown

readme.markdown

introduction

This document covers the basics of how to write node.js programs with streams.

"We should have some ways of connecting programs like garden hose--screw in
another segment when it becomes when it becomes necessary to massage data in
another way. This is the way of IO also."

Doug McIlroy. October 11, 1964


Streams come to us from the earliest days of unix and have proven themselves over the decades as a dependable way to compose large systems out of small components that do one thing well. In unix, streams are implemented by the shell with | pipes. In node, the built-in stream module is used by the core libraries and easily be used by user-land code. Similar to unix, the node stream module's primary composition operator is called .pipe().

Streams can be useful because they restrict the implementation surface area into a single consistent interface. You can then easily plug the output of one stream to the input of another and use libraries that operate abstractly on streams to institute higher-level flow control.

Streams are an important component of small-program design and unix philosophy but there are many other important abstractions worth considering. Just remember that technical debt is the enemy and seek the best abstractions for the problem at hand.


basics

readable

writable

pipe

backpressure


builtin streams

child_process.spawn()

fs.createReadStream()

fs.createWriteStream()

net.connect()

net.createServer()

http.request()

http.createServer()


control streams

through

pause-stream

concat-stream

duplex

mux-demux

emit-stream

invert-stream

map-stream

remote-events


state streams

cdrt

delta-stream


io streams

request

reconnect

kv


parser streams

tar

trumpet

JSONStream

json-scrape

trumpet


browser streams

shoe

domnode

sorta

graph-stream

arrow-keys


rpc streams

dnode

rpc-stream


test streams

tap

Something went wrong with that request. Please try again.