ExpressJS msgpack response middleware /[Node]
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Build Status Dependency Status

An implementation of Message Pack middleware for ExpressJS.


  • Automatic Message Pack detection (from the HTTP headers) and encoding of all JSON messages to Message Pack.
  • Extension of the current ExpressJS API; Introducing the Response.msgPack(jsObject) method on the standard ExpressJS Response object.

Getting Started

With auto-detection and transformation enabled, the middleware detects automatically the HTTP header Accept: application/x-msgpack and piggybacks the Response.json() method of the ExpressJS API, to encode the JSON response as Message Pack. This method is usefull, when you have existing applications that need use the middleware, without changing the codebase very much.

const msgpackResponse = require('msgpack-response');

app.use(msgpackResponse({auto_detect: true}));

app.get('/test_json', (req, res) => {
	res.status(200).json({'message': 'a true test'});

Note: Remember the add the header Accept: application/x-msgpack in the request.

Also it can have auto detection and transformation disabled. The middleware extends the Response object of the ExpressJS framework, by adding the msgPack() method to it. Then to return an encoded response, you just use the Response.msgPack() method that accepts the Javascript object as parameter. For example,

const msgpackResponse = require('msgpack-response');

app.use(msgpackResponse({auto_detect: false}));

app.get('/test_msgpack', (req, res) => {
	res.status(200).msgPack({'message': 'a true test'});

Note: Initialize the middleware before the actual routes in the middleware chain to properly extend the Response Object.


Node.js >= 6.0


With npm do:

npm install msgpack-response -save


This project is funded and maintained by Mobiltron, Inc.. We ❤️ open source software!

Check out our other open source projects or say 👋 on twitter @mobiltron.


Contributions are welcome 🤘 We encourage developers like you to help us improve the projects we've shared with the community. Please see the Contributing Guide and the Code of Conduct.


See also the list of contributors who participated in this project.


msgpack-response is available under the MIT license. See the LICENSE file for more info.