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 🙏

© 2024 – Pkg Stats / Ryan Hefner

body-bson

v1.0.13

Published

express/koa middleware to parse bson body.

Downloads

12

Readme

body-bson

express/koa middleware to parse bson body.

Example

For koa:

var Koa = require('koa');
var bodyBson = require('body-bson');
 
var app = new Koa();
app.use(bodyBson());
 
app.use(async ctx => {
  // the parsed body will store in ctx.request.body
  // if nothing was parsed, body will be undefined
  // body may contain value of bson types 
  var body = ctx.request.body;
});

For express

var express = require('express')
var bodyBson = require('body-bson')
 
var app = express()
 
// parse application/bson
app.use(bodyBson.json())
 
app.use(function (req, res) {
  // the parsed body will store in req.body
  // if nothing was parsed, body will be undefined
  // body may contain value of bson types 
  var body=  req.body;
})

API

bodyBson

var bodyBson = require('body-bson')

The bodyBson function is a factory to create middleware.

app.use(bodyBson(option))

The middleware will populate the request.rawBody property with the parsed body when the Content-Type request header matches the type option(default to application/bson), nothing would be modified if the Content-Type was not matched, or an error occurred.

bodyBson.bson

The default bson instance used by bodyBson. It's exported for convenience.

options

bson

Controls the bson instance to deserialize the body. One method is required for the instance: bson.deserialize(buffer). Defaults to instance created by [email protected].

limit

Controls the maximum request body size. If this is a number, then the value specifies the number of bytes; if it is a string, the value is passed to the bytes library for parsing. Defaults to '10mb'.

type

Controls the matching Content-Type headers, can pass a string or an array of strings. Defaults to 'application/bson'.

rawBody

Controls whether to generate request.rawBody to represent raw buffer received. request.rawBody will only be generated if request.rawBody should be generated. Defaults to false.