InfoQ Homepage News A New Streaming API for Node.js

A New Streaming API for Node.js

Leia em Português


Node.js, the server-side JavaScript platform built on top of Google’s V8 engine, has included a new Streaming API in its unstable 0.9.4 release. Nicknamed "streams2", it is scheduled to be included in the 0.10 stable release.

The new API protects against data loss by starting streams in a paused state, and waiting until a listener is attached before emitting ‘data’ events. Additionally, the paused state is now guaranteed to not emit any ‘data’ events, instead of being merely advisory. A new read() method is included, which allows an arbitrary number of bytes to be read from the stream, leaving the remaining for another program to consume.

The older methods and events are kept for backwards compatibility:

Readable streams switch into "old mode" when a 'data' event handler is added, or when the pause() or resume() methods are called. The effect is that, even if you are not using the new read() method and 'readable' event, you no longer have to worry about losing 'data' chunks.

An edge case is introduced - if no ‘data’ event handler is added, and the pause() and resume() methods are never called, the stream will never emit an ‘end’ event, and will remain paused forever.

A new Streams implementation has been discussed since the 0.4 release, but more pressing problems were always at hand, and it was considered too difficult to make backwards-compatible, required to ensure adoption. In 0.10, the bullet has finally been bit, and developers are encouraged to try it out and provide feedback.

Node.js is designed for building fast, scalable network applications, is developed by Joyent, Inc, as well as the open-source community, and is used by companies such as Microsoft, LinkedIn, and eBay.

We need your feedback

How might we improve InfoQ for you

Thank you for being an InfoQ reader.

Each year, we seek feedback from our readers to help us improve InfoQ. Would you mind spending 2 minutes to share your feedback in our short survey? Your feedback will directly help us continually evolve how we support you.

Take the Survey

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p


Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.