Adds support to express's res.json and res.jsonp methods for passing in a promise. Promise resolution is passed to the native method while exceptions go to error-handling middleware.

Usage no npm install needed!

<script type="module">
  import expressJsonPromise from '';


Build Status


Adds support for passing a promise directly to res.json and res.jsonp. A resolved promise has its result sent to the native implementation while a rejected one will automatically call error-handling middleware with the exception.


npm install --save express-json-promise

var app = express();


With express-json-promise, you can pass a promise for your async workflow directly to res.json and res.jsonp methods. If the promise is successful, the native res.json method is called for you with the result. If it rejects via an exception, that exception object is passed to express' next, triggering the error-handling middleware.

var app = express();
app.get('/foo', function (req, res) {
  var workflow = doSomethingAsync()
    .then(function (result) {
      if (result === 'happy') {
        // As this is the ultimate result of `workflow`, this will get
        // passed to `res.json` and to the client if all else is successful.
        return { result: 'stuff' };
      // No need to call res.json or set status!  Throw as per usual.
      throw new Error("Massive Failure!");
  res.json(workflow); // So easy!

// ErrorHandler will be triggered with the thrown exception above, just as one would expect!
app.use(function ErrorHandler(err, req, res, next) {
  res.status(500).json({ message: 'Something Failed!', details: err });


The options parameter to the middleware allows selection of which methods you wish to override. By default, it'll override both json and jsonp methods. Technically you can override any method on res, but not all will behave as you might expect.

app.use(require('express-json-promise')({ override: ['jsonp'] }));

By doing this, the json method will be left alone and retain its default lack-of-promisey-goodness support.

Why don't you just override send?