Skip to content

darnyelx/expressjs-route-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ExpressJs Route Manager

Writing and managing express routes can be tedious most times.

Express Route Manager helps you organize your routes and middlewares in a JSON file, helping you group routes out of the box. Express Route Manager is instinctively read.

Usage

Initialization

const express = require('express');
const expressRouteManager = require('expressjs-route-manager')(express,option);

Options (object)

option type description
option.routeFile STRING (compulsory) Path to route file
option.controllerDirectory STRING Path to controllers. Defaults ./
option.middlewareDirectory STRING Path to controllers. Defaults ./

Route File Configuration

Single Level
module.exports = {
url: {
     middlewares: ['middleware1', 'middleware2']
     controller: {
             path: 'controller',
             method: 'method'
         },
     verb: 'verb'
}

The above configuration would produce a url as thus: /url

Multi-Level

A multilevel configuration can be achieved as thus:

module.exports = {
"url1": {
   middlewares: ['middleware1', 'middleware2'],
  "url2": {
  "url3:params": {
    'url4': {
         controller: {
             path: 'auth',
             method: 'login'
         },
        verb: 'post'
    }
}

The above configuration would produce a url as thus: /url/url2/url3/url4

The middleware property can be applied at any level and it takes effect from that level downwards


Options

option type description
url STRING or Property Url level. Takes all ExpressJs url format e.g url/:params
middlewares ARRAY Array of path to middlewares. Note that this path is relative to the path set in "middlewareDirectory" in the initialization stage.
controller OBJECT/FUNCTION Object configuration of the controller
controller.path STRING Path to the controller file. Note that this path is relative to the path set in the initialization stage.
controller.method STRING Array of path to middlewares. Note that this path is relative to the path set in "controllerDirectory" in the initialization stage.
verb STRING Verb of the path. Takes all ExpressJs availble verbs. E.g "Post", "Get", "Put".etc. Defaults to "Get"

About

A library that helps you organize and group your expressjs route intuitively

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published