1.0.1 • Published 7 years ago
express-eventify v1.0.1
express-eventify
Converts an express app instance into an object which can subscribe to REST requests like events.
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
Donating
Please support this project via gratipay.