Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More

express-conditional-middleware

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-conditional-middleware

Allow express middlewares to be overridden based on a condition.


Version published
Weekly downloads
4.7K
decreased by-11.34%
Maintainers
1
Weekly downloads
 
Created

Express Conditional Middleware

Greenkeeper badge

travis build Coverage Status

This module provides a conditional middleware for express. Use as follows:

var conditional = require('express-conditional-middleware');

// Simple boolean method.
app.use(conditional(true, function (req, res, next) {
  // ...
});

// Function method.
app.use(conditional(
  function (req, res, next) {
    return req.get('accept') === 'application/json';
  },
  function (req, res, next) {
    // ...
  }
));

// Failure middleware.
app.use(conditional(
  function (req, res, next) {
    return req.get('accept') === 'application/json';
  },
  function (req, res, next) {
    // Executed if 'accept' === 'application/json'
  },
  function (req, res, next) {
    // Executed if 'accept' !== 'application/json'
  }
));

FAQs

Package last updated on 10 Jan 2018

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