1.0.1 • Published 6 years ago

router-for-express v1.0.1

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

Table of Contents

  1. router-for-express
  2. example of use
  3. generators
    1. folderBased
    2. objectBased
    3. mixed

router-for-express

An express route generator with several built-in generators, with the capability of adding user defined generators

example of use

Ussage: #+BEGINSRC js const express = require('express'); const expressGenerator = require('router-for-express');

app = express(); app.use(expressGenerator(src, expressGenerator.folderBased)); #+ENDSRC js Where src is the route to where your controllers(express middleware or endpoint) are located and expressGenerator.folderBased is a generator

generators

Built-in Generators are located in the export module object and include: `folderBased`, `objectBased` and `mixed`

folderBased

The folderBased generator generate routes givin a folder structure of the specified path, for example this folder structure:

src:
 |
 ----`index.js`
 |
 ----`create.js`
 |
 ----`+id`
     |
     ----`details.js`

Would generate routes for `/`, `/create` and `/:id/details`, This files should export a function or an object, The object is in the form `{ get: function(req, res, next) { }, post: function(req, res, next) { }, ` and so on for each request type If the file export a function then the default action (all) is used.

objectBased

The objectBased generator generate routes for a single object with the specified path by src param, for example routes.js: #+BEGINSRC js module.exports = { get: function(req, res, next) { }, create: function(req, res, next) { }, ':id': { details: { get: function(req, res, next) { }, post: function(req, res, next) { }, put: function(req, res, next) { } } } } #+ENDSRC js Would generate routes for `get /`, `all /create`, `get /:id/details`, `post /:id/details`

mixed

The mixed generator is a mixed of both of the previous generators allowing a complex folder structure and a complex object structure as well