Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Node Cookbook: Second Edition
  • Table Of Contents Toc
Node Cookbook: Second Edition

Node Cookbook: Second Edition

By : David Mark Clements
4.3 (7)
close
close
Node Cookbook: Second Edition

Node Cookbook: Second Edition

4.3 (7)
By: David Mark Clements

Overview of this book

In Node Cookbook Second Edition, each chapter focuses on a different aspect of working with Node. Following a Cookbook structure, the recipes are written in an easy-to-understand language. Readers will find it easier to grasp even the complex recipes which are backed by lots of illustrations, tips, and hints. If you have some knowledge of JavaScript and want to build fast, efficient, scalable client-server solutions, then Node Cookbook Second Edition is for you. Knowledge of Node will be an advantage but is not required. Experienced users of Node will be able to improve their skills.
Table of Contents (18 chapters)
close
close
Node Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1
Index

Consuming streams


As of Node v0.10.x, every readable stream has a read method that can be used to access data that's loaded into our read stream. Prior to Node v0.10.x, chunks of data were captured by listening to a data event; we can still do this when it is suitable (see the There's More… section) but this depends on the use case; therefore using the read method instead can be cleaner.

In this recipe, we're going to receive a stream from the Couch database that backs the npm registry and simply log out everything we get.

Getting ready

All we need to do is create a file named npm_stream_receiver.js.

How to do it…

We're going use the response object returned from an http.get call as our readable stream and set up some initial variables, so we'll require the http module as shown in the following code:

var http = require('http'), feed = 'http://isaacs.iriscouch.com/registry/_changes?feed=continuous', ready = false; 

We'll pass the feed variable to http.get.

The ready variable is being used to introduce...

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Node Cookbook: Second Edition
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon