1.2.0 • Published 8 years ago

express-file-autorouter v1.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

An express auto-router through reading name of file

Installation

Install package with NPM and add it to your dependencies:

npm install --save express-file-autorouter

Usage

If your directory of saving routes like this:

project
│
└─routerPath
    │  router1.js
    │  router2.js
    │  router3.js
    │
    └─ routerDir
         router4.js
         router5.js

In app.js or routes init file:

var AutoRouter = require('express-file-autorouter');
var path = require('path');
var app = require('express')();

var autoRouter = new AutoRouter({
    routerPath: path.resolve(__dirname, 'routerPath'),
    app: app,
    alias: {
        '/routerDir/router5' : '/change5'
    }
});

console.log(Object.keys(autoRouter.getRouters()));

Now express-file-autorouter will create the following routes:

[
	'/router1',
	'/router2',      
	'/router3',
	'/routerDir/router4',
	'/change5'   //alias: /routerDir/router5 => change5
]
1.2.0

8 years ago

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago