Skip to content
This repository has been archived by the owner on Mar 28, 2018. It is now read-only.

Latest commit

 

History

History
70 lines (62 loc) · 3 KB

README.md

File metadata and controls

70 lines (62 loc) · 3 KB

express-eventify

Converts an express app instance into an object which can subscribe to REST requests like events.

Greenkeeper badge Travis Dependency Status David Version npm npm Downloads license Gratipay User Package Quality

NPM Package Quality


Installation

# Install via NPM
npm install express-eventify
# OR
# Install via Yarn
yarn add express-eventify

Usage

express-eventify extends an express app by introducing the $on function.

Initialize

const express = require('express');
const eventify = require('express-eventify');

// create a new express app
let app = express();
// initialize the new express app
app = eventify(app);

Subscribe

There are two ways of subscribing to express with express-eventify

// notice the '!' - it seperates the REST method and the path i.e. "{method}!{path}"
// in this case it's 'get' and '/'
app.$on("get!/", (req, res) => res.send("Using express-eventify")); 

The second way discribes shows how the $on function consumes an object as a parameter.

app.$on({
    get: {
        "/": function(req, res) {
            // all parameters passed to a normal express method 
            // are also sent to this callback (request, response, next, etc..)
        }
    },
    post: {
        // post routes
    }
});

Notes

The following express methods are wrapped by express-eventify:

  • delete
  • get
  • param
  • post
  • put
  • render

License

MIT


Donating

Please support this project via gratipay.

Support via Gratipay