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

1.3.3 • Public • Published

express-chocola

A small framework around express Routers providing an alternate way of defining routes in express.

Table of Contents

Features

  • Easy & readable way of defining and navigating through different routes
  • Better route organization by concept of naming, grouping and labeling
  • Register route group with own middleware
  • Label routes with tags that carry own middleware
  • Dynamic route finding & registering
  • Automatic checking on inputs to routes in query, params & body

Installing

$ npm install express-chocola

Quick Start

Initialize the RouteRegistry and express where we want to look for our routes as a regexp. Then acces the express router by the router member on the registry

index.js

import express from 'express';
import path from 'path';
import { RouteRegistry } from 'express-chocola';

const app = express();
const registry = new RouteRegistry()
  .registerDefaultGroup()
  .registerRoutesIn({
    filter: /^([^.].*)\.(js|ts)$/,
    dirname: path.join(__dirname, 'routes'),
  });

app.use(registry.router);

Define a route by extending the base Route class

routes/chocola.js

import { Route } from 'express-chocola';

export default class Default extends Route {
  constructor() {
    super({
      name: 'default',
      method: 'get',
      path: '',
    });
  }

  async run(args) {
    const { response } = args;
    return response.send('Welcome to La Soleil!');
  }
}

Readme

Keywords

Package Sidebar

Install

npm i express-chocola

Weekly Downloads

1

Version

1.3.3

License

ISC

Unpacked Size

84.5 kB

Total Files

23

Last publish

Collaborators

  • tifye