Socket
Socket
Sign inDemoInstall

body-parser

Package Overview
Dependencies
Maintainers
6
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

body-parser - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

7

HISTORY.md

@@ -0,3 +1,8 @@

1.1.0 / 2014-05-10
==================
1.0.1 / 2014-04-14
* add `type` option
* deps: pin for safety and consistency
1.0.2 / 2014-04-14
==================

@@ -4,0 +9,0 @@

@@ -12,5 +12,16 @@

function bodyParser(options){
var _urlencoded = urlencoded(options);
var _json = json(options);
var opts = {}
options = options || {}
// exclude type option
for (var prop in options) {
if ('type' !== prop) {
opts[prop] = options[prop]
}
}
var _urlencoded = urlencoded(opts)
var _json = json(opts)
return function bodyParser(req, res, next) {

@@ -26,3 +37,5 @@ _json(req, res, function(err){

options = options || {};
var strict = options.strict !== false;
var type = options.type || 'json';

@@ -33,3 +46,3 @@ return function jsonParser(req, res, next) {

if (!typeis(req, 'json')) return next();
if (!typeis(req, type)) return next();

@@ -69,2 +82,4 @@ // flag as parsed

var type = options.type || 'urlencoded';
return function urlencodedParser(req, res, next) {

@@ -74,3 +89,3 @@ if (req._body) return next();

if (!typeis(req, 'urlencoded')) return next();
if (!typeis(req, type)) return next();

@@ -77,0 +92,0 @@ // flag as parsed

20

package.json
{
"name": "body-parser",
"description": "Connect's body parsing middleware",
"version": "1.0.2",
"version": "1.1.0",
"author": {

@@ -14,15 +14,17 @@ "name": "Jonathan Ong",

"dependencies": {
"type-is": "~1.1.0",
"raw-body": "~1.1.2",
"qs": "~0.6.6"
"type-is": "1.1.0",
"raw-body": "1.1.4",
"qs": "0.6.6"
},
"devDependencies": {
"connect": "*",
"mocha": "*",
"should": "*",
"supertest": "*"
"mocha": "~1.18.2",
"should": "~3.3.1",
"supertest": "~0.12.1"
},
"engines": {
"node": ">= 0.8"
},
"scripts": {
"test": "make test"
"test": "mocha --require should --reporter spec --bail"
}
}

@@ -1,38 +0,73 @@

# Body Parser [![Build Status](https://travis-ci.org/expressjs/body-parser.png)](https://travis-ci.org/expressjs/body-parser)
# body-parser [![Build Status](https://travis-ci.org/expressjs/body-parser.svg?branch=master)](https://travis-ci.org/expressjs/body-parser) [![NPM version](https://badge.fury.io/js/body-parser.svg)](https://badge.fury.io/js/body-parser)
Connect's body parsing middleware.
Node.js body parsing middleware.
This only handles `urlencoded` and `json` bodies.
For multipart bodies, you may be interested in the following modules:
- [busboy](https://github.com/mscdex/busboy) and [connect-busboy](https://github.com/mscdex/connect-busboy)
- [multiparty](https://github.com/andrewrk/node-multiparty) and [connect-multiparty](https://github.com/andrewrk/connect-multiparty)
- [formidable](https://github.com/felixge/node-formidable)
- [multer](https://github.com/expressjs/multer)
Other body parsers you might be interested in:
- [body](https://github.com/raynos/body)
- [co-body](https://github.com/visionmedia/co-body)
## Installation
```sh
$ npm install body-parser
```
## API
```js
var bodyParser = require('body-parser');
var express = require('express')
var bodyParser = require('body-parser')
var app = connect();
var app = express()
app.use(bodyParser());
// parse application/json and application/x-www-form-urlencoded
app.use(bodyParser())
// parse application/vnd.api+json as json
app.use(bodyParser.json({ type: 'application/vnd.api+json' }))
app.use(function (req, res, next) {
console.log(req.body) // populated!
next();
next()
})
```
### bodyParser([options])
### bodyParser(options)
Returns middleware that parses both `json` and `urlencoded`. The `options` are passed to both middleware.
Returns middleware that parses both `json` and `urlencoded`.
The `options` are passed to both middleware, except `type`.
### bodyParser.json([options])
### bodyParser.json(options)
Returns middleware that only parses `json`. The options are:
- `strict` <true> - only parse objects and arrays
- `limit` <1mb> - maximum request body size
- `strict` - only parse objects and arrays. (default: `true`)
- `limit` - maximum request body size. (default: `<100kb>`)
- `reviver` - passed to `JSON.parse()`
- `type` - request content-type to parse (default: `json`)
### bodyParser.urlencoded([options])
The `type` argument is passed directly to the [type-is](https://github.com/expressjs/type-is) library. This can be an extension name (like `json`), a mime type (like `application/json`), or a mime time with a wildcard (like `*/json`).
### bodyParser.urlencoded(options)
Returns middleware that only parses `urlencoded` with the [qs](https://github.com/visionmedia/node-querystring) module. The options are:
- `limit` <1mb> - maximum request body size
- `limit` - maximum request body size. (default: `<100kb>`)
- `type` - request content-type to parse (default: `urlencoded`)
The `type` argument is passed directly to the [type-is](https://github.com/expressjs/type-is) library. This can be an extension name (like `urlencoded`), a mime type (like `application/x-www-form-urlencoded`), or a mime time with a wildcard (like `*/x-www-form-urlencoded`).
### req.body
A new `body` object containing the parsed data is populated on the `request` object after the middleware.
## License

@@ -39,0 +74,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc