body-parser-with-msgpack
raw JSON → 1.17.0 verified Sat May 09 auth: no javascript
Express-compatible body parsing middleware for Node.js (v1.17.0) that extends the popular body-parser module with MessagePack (msgpack) support. In addition to JSON, URL-encoded, raw, and text parsers, it provides a dedicated msgpack parser for binary MessagePack requests. Maintained as a fork, it includes automatic gzip/deflate inflation, configurable limits, and strict mode. Compatible with Node >= 0.8, intended for use with Express or Connect.
Common errors
error TypeError: bodyParser.json is not a function ↓
cause Package not installed or required incorrectly.
fix
Run 'npm install body-parser-with-msgpack' and use 'const bodyParser = require("body-parser-with-msgpack")'.
error Error: Cannot find module 'msgpack5' ↓
cause Missing msgpack5 dependency (should be bundled).
fix
Install the package: 'npm install body-parser-with-msgpack' or if using npm < 3, install msgpack5 manually: 'npm install msgpack5'.
error ReferenceError: bodyParser is not defined ↓
cause Forgetting to import/require the module.
fix
Add 'const bodyParser = require("body-parser-with-msgpack")' at the top of your file.
Warnings
gotcha The msgpack parser uses msgpack5 library internally; it does not support the full MessagePack spec extensions. ↓
fix If you need full MessagePack support (e.g., timestamps, custom types), consider using msgpack5 directly or another library.
gotcha Parsed MessagePack body may be a Buffer (for binary data) or an object/array. Ensure your handler checks the type. ↓
fix Use Buffer.isBuffer(req.body) to detect binary data, or rely on msgpack5 behavior.
deprecated The 'inflation' option in earlier versions was misspelled 'infalting'. ↓
fix Use 'inflate' option instead of 'infalting'.
gotcha This package does not handle multipart bodies. Use busboy, formidable, or multer for multipart. ↓
fix Use the recommended modules for multipart parsing.
Install
npm install body-parser-with-msgpack yarn add body-parser-with-msgpack pnpm add body-parser-with-msgpack Imports
- bodyParser wrong
import bodyParser from 'body-parser-with-msgpack'correctconst bodyParser = require('body-parser-with-msgpack') - bodyParser.json wrong
bodyParser.JSON()correctbodyParser.json({ limit: '1mb' }) - bodyParser.msgpack wrong
bodyParser.messagepack() or bodyParser.msgpack() from body-parsercorrectbodyParser.msgpack({ limit: '2mb' })
Quickstart
const express = require('express');
const bodyParser = require('body-parser-with-msgpack');
const app = express();
// Parse JSON bodies
app.use(bodyParser.json());
// Parse MessagePack bodies
app.use(bodyParser.msgpack({ limit: '2mb' }));
app.post('/data', (req, res) => {
res.json({
received: req.body,
type: typeof req.body === 'object' ? 'object' : 'other'
});
});
app.listen(3000, () => console.log('Server running on port 3000'));