# router-for-express

> An express router module

Latest version **1.0.1** (published 2017-11-29) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install router-for-express
pnpm add router-for-express
yarn add router-for-express
bun add router-for-express
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-11-29 |
| First published | 2017-11-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Daniel Perez Alvarez |
| Maintainers | danielpanpm |

## Links

- npm: https://www.npmjs.com/package/router-for-express
- Repository: https://github.com/danielpa9708/express-router
- Homepage: https://github.com/danielpa9708/express-router#readme
- Issues: https://github.com/danielpa9708/express-router/issues
- npm.io page: https://npm.io/package/router-for-express

## Dependencies (1)

- [express](https://npm.io/package/express.md) ^4.14.1

## Recent versions

- 1.0.1 (latest) — 2017-11-29
- 1.0.0 — 2017-11-29

## README

# Table of Contents

1.  [router-for-express](#orgacc621b)
2.  [example of use](#org8d244ee)
3.  [generators](#org033774d)
    1.  [folderBased](#orgd56e4e9)
    2.  [objectBased](#org3604065)
    3.  [mixed](#org7374668)


<a id="orgacc621b"></a>

# router-for-express

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


<a id="org8d244ee"></a>

# example of use

  Ussage:
     #+BEGIN<sub>SRC</sub> js
const express = require('express');
const expressGenerator = require('router-for-express');

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


<a id="org033774d"></a>

# generators

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


<a id="orgd56e4e9"></a>

## 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) { &#x2026; }, post: function(req, res, next) { &#x2026; }, &#x2026;\` and so on for each request type
If the file export a function then the default action (all) is used.


<a id="org3604065"></a>

## objectBased

   The objectBased generator generate routes for a single object with the specified path by src param, for example routes.js:
     #+BEGIN<sub>SRC</sub> js
module.exports = {
  get: function(req, res, next) { &#x2026; },
  create: function(req, res, next) { &#x2026; },
  ':id': {
    details: {
      get: function(req, res, next) { &#x2026; },
      post: function(req, res, next) { &#x2026; },
      put: function(req, res, next) { &#x2026; }
    }
  }
}
     #+END<sub>SRC</sub> js
     Would generate routes for \`get /\`, \`all /create\`, \`get /:id/details\`, \`post /:id/details\` &#x2026;


<a id="org7374668"></a>

## 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

---
_Source: https://npm.io/package/router-for-express · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
