GithubHelp home page GithubHelp logo

node-mware's Introduction

mware

Build Status Coverage Status

mware is a utility for creating a middleware stack with any node or browser application. Inspired by the middleware pattern in connect.

Usage

import mware from 'mware';
const { use, run } = mware();

// add middleware
use((ctx, next) => {
    console.assert(ctx === context);

    return next();                     // next middleware
    return next(null, true);           // stop the stack
    return next(new Error('oopsies')); // stop and report error
});

// run stack
const context = {};
run([context], (err) => {
    if (err) throw err;
    console.log('stack complete');
});

Installation

NPM

npm install --save mware

Yarn

yarn add mware

API

mware()

Returns a mware instance.

Instance

#use(fn...)
  • fn: Function|[]Function, Middleware functions to add to stack.
#run([args], [done])
  • args: []*, List of arguments to pass to each middleware function.
  • done: Function, Callback for when the middleware stack has stopped.

Async/await

For an async/await approach see mware-async.

License

MIT

Copyright (c) 2016 Christopher Turner

node-mware's People

Contributors

tur-nr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

h2non 9technology

node-mware's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.