0.0.4 • Published 3 years ago

@ansuz-dev/async-router v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Asynchronous Express Router

Installation

Using npm:

npm install --save @ansuz-dev/async-router

Usage

Async router

const express = require("express");
const app = express();

const { Router } = require("@ansuz-dev/async-router");
const router = new Router();

// middleware
router.use(async (req, res) => {
  console.log("%s %s", req.method, req.path);
});

// a route
router.get("/", async (req, res) => {
  res.json({ message: "connect" });
});

// another route with 2 callbacks
router.get("/2", async (req, res) => {
  req.data = "two";
}, async (req, res) => {
  let message = `${req.data} callbacks`;
  res.json({ message });
});

// always invoked
router.use(async (req, res) => {
  console.log("%s %s DONE", req.method, req.path);
});

app.use("/", router._);

Access Express router

You could access Express router object to implement the traditional callback.

router._.get("/express", (req, res, next) => {
  res.json({ message: "express router" });
});

API

Async router supports all methods of Express router:

router.all()
router.param()
router.route()
router.use()
router.MEDTHOD()

License

MIT

0.0.4

3 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago