npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

bulkbadger

v1.0.0

Published

batch ldjson suitable for couchdb's _bulk_docs

Readme

BulkBadger

Takes a stream of Line Delimited JSON, e.g. from MongoDB Queries, PostgreSQL (> 9.2) Queries or from the filesystem and makes them suitable for bulk imports into other systems, most notably CouchDB, by batching the line delimited JSON.

stream.pipe(new BulkBadger({chunksize: 300}).pipe(outputStream)

Input:

{"rocko": "artischocko"}
{"zett": "zettmeister"}
{"mr": "mussie"}

Output:

{"docs": [
  {"rocko": "artischocko"},
  {"zett": "zettmeister"},
  {"mr": "mussie"}
]}

Output chunksize set to 2:

[
  {"docs":[{"rocko":"artischocko"},{"zett":"zettmeister"}]},
  {"docs":[{"mr":"mussie"}]}
]

Options

chunksize:        amount of docs in each chunk, default: 200

Examples

Use a regular JSON file from the fs as input

testjson.json:

[
  {"a": "b"},
  {"b": "c"},
  {"c": "d"}
]
var BulkBadger = require('bulkbadger')

var fs = require('fs')
var JSONStream = require('JSONStream')

fs
  .createReadStream('./testjson.json')
  .pipe(JSONStream.parse('*'))
  .pipe(new BulkBadger({chunksize: 2}))
  .pipe(JSONStream.stringify())
  .pipe(process.stdout)

Use a CSV file as input

var BulkBadger = require('bulkbadger')

var parse = require('csv-parse')
var fs = require('fs')
var transform = require('stream-transform')
var JSONStream = require('JSONStream')


var parser = parse({comment: '#', delimiter: ':'})
var input = fs.createReadStream('/etc/passwd')


var transformer = transform(function (record, cb) {

  var username = record[0]
  var pw = record[1]
  var uid = record[2]
  var gid = record[3]
  var comment = record[4]
  var home = record[5]
  var shell = record[6]

  cb(null, {
    id: username,
    pw: pw,
    uid: uid,
    gid: gid,
    comment: comment,
    home: home,
    shell: shell
  })

})

input
  .pipe(parser)
  .pipe(transformer)
  .pipe(new BulkBadger({chunksize: 2}))
  .pipe(JSONStream.stringify())
  .pipe(process.stdout)

Stream from MongoDB into CouchDB

var MongoClient = require('mongodb').MongoClient
var BulkBadger = require('bulkbadger')
var CouchBulkImporter = require('./index.js').CouchBulkImporter

var url = 'mongodb://localhost:27017/test'
// Use connect method to connect to the Server
MongoClient.connect(url, function (err, db) {
  console.log('Connected correctly to server')
  var col = db.collection('restaurants')
  var stream = col.find({}, {})
  stream
    .pipe(new BulkBadger({chunksize: 300}))
    .pipe(new CouchBulkImporter({
      url: 'http://tester:testerpass@localhost:5984/restaurant'
    })).on('error', function (e) {
      console.log('Oh noes!')
      console.log(e)
    })

  stream.on('error', function (e) {
    console.log('Oh noes!')
    console.log(e)
  })
  stream.on('end', function () {
    console.log('migration finished')
    db.close()
  })
})

Use Line-Delimited JSON as input

ldjson.json:

{"rocko": "artischocko"}
{"zett": "zettmeister"}
{"mr": "mussie"}
var fs = require('fs')
var JSONStream = require('JSONStream')

var BulkBadger = require('bulkbadger')

fs
  .createReadStream(__dirname + '/ldjson.json')
  .pipe(JSONStream.parse())
  .pipe(new BulkBadger({chunksize: 2}))
  .pipe(JSONStream.stringify())
  .pipe(process.stdout)