Registry / devops / bodymen

bodymen

JSON →
library1.1.1jsnpmunverified

Body parser middleware for Express that formats, validates, and parses request bodies against a Mongoose-like schema. Current stable version is 1.1.1, with no recent releases. It mirrors Querymen's functionality but for request bodies instead of query strings. Requires body-parser. Released under MIT.

npm install bodymen
INSTALL
IMPORT
SIG · BODYMEN
B
bodymen
devopsjavascriptv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default export (function)
import bodymen from 'bodymen'
import { bodymen } from 'bodymen'
bodymen is a default export (a function). Named destructuring will fail.
errorHandler
import { errorHandler } from 'bodymen'
errorHandler is a named export. Use destructuring.
middleware function
import bodymen from 'bodymen'; app.use('/path', bodymen.middleware(schema), handler)
import { middleware } from 'bodymen'
The middleware function is accessed as a property (bodymen.middleware) of the default export.

Shows how to set up bodymen middleware with schema validation and error handling in an Express app.

import express from 'express'; import bodyParser from 'body-parser'; import bodymen, { errorHandler } from 'bodymen'; const app = express(); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); const schema = { title: { type: String, required: true, trim: true, minlength: 3 }, content: { type: String, required: true, minlength: 32 }, tags: [String] }; app.post('/posts', bodymen.middleware(schema), (req, res) => { res.json(req.bodymen.body); }); app.use(errorHandler()); app.listen(3000);
Debug
Known issues
gotchaBodymen requires body-parser to be applied before its middleware.
fix
Ensure body-parser (urlencoded or json) is used before bodymen.middleware().
affects: >=0
gotchaThe parsed body is available at req.bodymen.body, not req.body.
fix
Access the validated body via req.bodymen.body.
affects: >=0
gotchaBodymen uses ESM (import) syntax; CommonJS require may not work without transpilation.
fix
Use import syntax or ensure your environment supports ESM (Node >=13) or use a bundler.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: bodymen.middleware is not a function
Importing bodymen incorrectly (e.g., as a named import).
fix
Use default import: import bodymen from 'bodymen'
Cannot read property 'body' of undefined (req.bodymen is undefined)
body-parser middleware not attached before bodymen.middleware().
fix
Add app.use(bodyParser.urlencoded({ extended: false })) and app.use(bodyParser.json()) before the route.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
expressrequiredBodymen is middleware designed to work with Express.
body-parserrequiredExpress middleware to parse request bodies; must be used before bodymen.
Agent activity
5 hits · last 30 days
node
4
Resources
bodymen — npm install bodymen · libregistry