bodymen

Body parser middleware for MongoDB, Express and Nodejs

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
bodymen
48191.1.14 years ago8 years agoMinified + gzip package size for bodymen in KB

Readme

bodymen
!NPM versionnpm-imagenpm-url !Build Statustravis-imagetravis-url !Coveralls Statuscoveralls-imagecoveralls-url !Dependency Statusdepstat-imagedepstat-url !Downloadsdownload-badgenpm-url
Bodymen works similarly to Querymen and has almost the same functionality, expect it formats, validates and parses request body instead of querystrings. Refer to Querymen's readme to find out more.

Prerequisites

You must use a request body parser like express body-parser and set it up before using bodymen:
import express from 'express'
import bodyParser from 'body-parser'

const app = express()

app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

Install

npm install --save bodymen

Usage

Bodymen allows you to define a schema to control the fields sent through the request body.
import bodymen, { errorHandler } from "bodymen"

app.post('/posts', bodymen.middleware({
  title: {
    type: String,
    required: true,
    trim: true,
    minlength: 3
  },
  content: {
    type: String,
    required: true,
    minlength: 32
  },
  tags: [String]
}), (req, res) => {
  console.log(req.bodymen.body) // will contain the parsed body
})

app.use(errorHandler()) // will send standard error messages, similar to Querymen

License

MIT © Diego Haz