json-from-promise
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

json-from-promise

Small Express connect-middlewere that sends json-response from your promise and errors with next.

Examples

CommonJS

const jsonFromPromise = require('json-from-promise').jsonFromPromise
app.get('/ping/:id', jsonFromPromise(function(req) {
  const id = req.params.id
  return Promise.resolve({
    pong: id
  })  

ES6

import { jsonFromPromise } from 'json-from-promise'
app.get('/ping/:id', jsonFromPromise(req => Promise.resolve({
  pong: req.params.id
})  

Note that you should (always) have a error-handler at the end of your application. If you don't you will get a unhandle promise rejection.

Readme

Keywords

none

Package Sidebar

Install

npm i json-from-promise

Weekly Downloads

6

Version

1.0.1

License

MIT

Unpacked Size

4.43 kB

Total Files

8

Last publish

Collaborators

  • tryggingamidstodin