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

Making stream interfaces


The Consuming streams and Playing with pipes recipes show us how to initiate and interact with various stream interfaces, such as the fs module's read and write streams, the http module's response object's write stream, and third-party modules, such as JSONStream (refer to the There's More… section of Playing with pipes).

In this recipe, we're going to make our own basic read and write stream interfaces.

Getting ready

Let's create and open a file, which we'll name basic_streams.js.

How to do it…

Node's stream module contains some base constructors to create streams. So, let's require the stream module and instantiate a readable stream as well as a writable stream:

var stream = require('stream'); 
var writable = new stream.Writable(); 
var readable = new stream.Readable(); 
var store = [];

We've also created an empty array named store. We'll be writing to store via the writable stream and reading from it with the readable stream.

To create streams that we intend to reuse...

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