Socket
Book a DemoInstallSign in
Socket

promisify-express

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promisify-express

A lightweight wrapper for Express 4's Router that allows middleware to return promises

4.0.1
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

promisify-express

This package allows you to wrap express so that you can use promises as handlers, and any promise error will be neatly passed to express error handlers.

Getting Started

Install the module with: npm install promisify-express --save.

Documentation

Middleware and route handlers can simply return a promise. If the promise is rejected, promisify-express will call next with the reason. This functionality removes the need to explicitly define a rejection handler.

// Without promisify-express
const express = require('express')
const app = express()

app.get('/url', async (req, res, next) => {
  try {
    throw new Error('something went wrong')
  } catch (e) {
    next(e)
  }
})

app.use((err, req, res, next) => {
  console.error(err)
  res.status(500).send(err.message)
})

// With promisify-express
const express = require('express')
const promisifyExpress = require('promisify-express')
const app = express()
promisifyExpress(app)

app.get('/url', async (req, res, next) => {
  throw new Error('something went wrong')
})

app.use((err, req, res, next) => {
  console.error(err)
  res.status(500).send(err.message)
})

Keywords

express

FAQs

Package last updated on 10 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.