Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Playing with Stream and Nodejs
var request = require("request");
var zlib = require("zlib");
var csv = require("csv-streamify");
var Handlebars = require("handlebars");
var es = require("event-stream");
var tmpl = Handlebars.compile("<li><a href="{{URL}}">{{Name}}</a> ({{City}})</li>");
// HTTP GET Request
request("http://nodestreams.com/input/people.csv.gz")
// Un-Gzip
.pipe(zlib.createGunzip())
// Parse CSV as Object
.pipe(csv({objectMode: true, columns: true}))
// Convert Object w/ Handlebars
.pipe(es.mapSync(tmpl))
// Join Strings
.pipe(es.join("\n"))
// Concat Strings
.pipe(es.wait())
// Wrap Strings
.pipe(es.mapSync(function(data) { return "<ul>" + data + "\n</ul>"; }));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment