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);
Errors
Common errors & fixes
TypeError: bodymen.middleware is not a function
Importing bodymen incorrectly (e.g., as a named import).
fixUse default import: import bodymen from 'bodymen'
Cannot read property 'body' of undefined (req.bodymen is undefined)
body-parser middleware not attached before bodymen.middleware().
fixAdd app.use(bodyParser.urlencoded({ extended: false })) and app.use(bodyParser.json()) before the route. Audit
Dependencies
expressrequiredBodymen is middleware designed to work with Express.
body-parserrequiredExpress middleware to parse request bodies; must be used before bodymen.