express-conditional-middleware
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/express-conditional-middleware package

2.1.1 • Public • Published

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'
  }
));

Readme

Keywords

none

Package Sidebar

Install

npm i express-conditional-middleware

Weekly Downloads

4,655

Version

2.1.1

License

MIT

Last publish

Collaborators

  • elliotttf