This package has been deprecated

Author message:

Package no longer supported. Contact support@npmjs.com for more info.

router-for-express

1.0.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i router-for-express

Weekly Downloads

1

Version

1.0.1

License

ISC

Last publish

Collaborators

  • npm