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

Table of Contents (18 chapters)
close
close
Node Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1
Index

Streaming across Node processes


Streams are about facilitating efficient, low memory data transfer, and processing; not just to and from the filesystem, but also to other processes and across network sockets.

In this recipe, we're going to write some simple command-line stream apps, then mix and match them with the common stream processing apps written in other languages.

Getting ready

Let's create two files: text_stream.js and uppercaser.js. Both of these need to be executable files as we're going to run them directly as command-line apps:

touch text_stream.js && chmod +x text_stream.js
touch uppercaser.js && chmod + x uppercaser.js

How to do it…

Let's start by making a readable stream that randomly pushes lowercase alphabetical letters to its reader and pipes the stream to process.stdout. In text_stream.js, we will write:

#!/usr/bin/env node 

var stream = require('stream'); 
var util = require('util'); 
var textStream; 

function TextStream() { 
    stream.Readable.call(this...
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