Skip to content

Instantly share code, notes, and snippets.

@rvagg
Created January 24, 2014 11:38
Show Gist options
  • Select an option

  • Save rvagg/8595846 to your computer and use it in GitHub Desktop.

Select an option

Save rvagg/8595846 to your computer and use it in GitHub Desktop.
Stream example
var request = require('request')
, json = require('JSONStream')
, through2 = require('through2')
, csv = require('csv-write-stream')
, zlib = require('zlib')
, fs = require('fs')
request({url: 'https://registry.npmjs.org/-/all'})
.pipe(json.parse('*'))
.pipe(through2.obj(function (data, enc, callback) {
if (data.name && data.description)
this.push({ name: data.name, description: data.description })
callback()
}))
.pipe(csv({ headers: [ 'name', 'description' ] }))
.pipe(zlib.createGzip())
.pipe(fs.createWriteStream('npm.csv.gz'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment