express-component
TypeScript icon, indicating that this package has built-in type declarations

4.0.1 • Public • Published

express-component

Component-based routing on top of Express

import * as express from "express"
import {withRouterFactory, Router, Get, HandleFn, TryJson, Component, Handler, GetTryJson} from "express-component";

class MyComponent implements Component {
  nice: HandleFn = (req, res) => ({nice: "nice"})

  handleCatch = (err: any) => {
    console.error(err)
  }

  getChildContext() {
    return "The context!"
  }

  render() {
    return new Router({
      path: "/api",
      children: [
        new GetTryJson({
          path: "/nice",
          child: this.nice,
          onCatch: this.handleCatch
        })
      ]
    })
  }
}

const app = express()
withRouterFactory(express.Router)(new MyComponent(), app)
app.listen(9090)

Readme

Keywords

none

Package Sidebar

Install

npm i express-component

Weekly Downloads

41

Version

4.0.1

License

ISC

Unpacked Size

30.1 kB

Total Files

57

Last publish

Collaborators

  • kobiburnley
  • npmjsfyber