router-for-express

An express router module

Package no longer supported. Contact support@npmjs.com for more info.
Last updated 4 years ago by danielpanpm .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install router-for-express 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.0.1                                ...           latest (4 years ago)

2 Versions

  • 1.0.1 [deprecated]           ...           4 years ago
  • 1.0.0 [deprecated]           ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2021 © npmmirror.com |