Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

express-dynamic-router

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-dynamic-router

provide dynamic routing system for express

latest
npmnpm
Version
0.2.7
Version published
Maintainers
1
Created
Source

express-dynamic-router

Build Status NPM version

Dynamic routing system for express.

author : Yuki Takei(MikeTOKYO)
email : yuki@miketokyo.com

##Overseas express-dynamic-router provide you the auto routing system for express.

You don't need to write routing codes written in express docs

app.get("hellow/world", hellow.world);
app.post("hellow/world", hellow.world);
app.put("hellow/world", hellow.world);
app.delete("hellow/world", hellow.world);

You only have to write easy code like bellow

require('express-dynamic-router')
.index(require('routes/index').index)
.register(app);

##Instalation

npm install express-dynamic-router

##Usage

express/app.js

app.configure('development', function(){
  app.use(express.errorHandler());
});

//use express-dynamic-router
require('express-dynamic-router')
.index(require('routes/index').index) // Set action for index
.register(app);

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

If you change routes dir, You only have to add setRoutesDir(path-your-route-dir) on method chain

require('express-dynamic-router')
.index(require('routes/index').index)
.setRoutesDir("path-to-your-routes")
.register(app);

##Api Reference

register

Register all routes in your routes dir except for actions which are ignored.

dynamicRouter.register(object expressApp)

setRoutesDir

Set path to your routes dir (First, dynamic-router browse express/routes, if you don't use this method.)

dynamicRouter.setRoutesDir(string path-to-your-custome-routes-dir)

getRoutesDir

Get your routes dir string.

dynamicRouter.getRoutesDir()

index

Set index action (accessible http://your-domain.com/)

dynamicRouter.index(function indexAction)

applyOnly

Register only routes which are given arguments.

dynamicRouter.applyOnly(['routes1', '....'])

■usage

dynamicRouter
.applyOnly(['user', 'account'])
})
.register('app);
# GET   /user/index   -> 200 OK
# POST  /account/save -> 201 Created
# GET   /mypage/index -> 404 Not Found

ignore

Set ignore actions which you not want to register.

dynamicRouter.ignore(object ignoreAction)

■usage

dynamicRouter
.ignore({
  '/*' : ['hogehoge', 'fugafuga'], // apply ignoreing to all routes.
  'user' : ['initialize', 'beforeRenderHook'] // apply ignoreing to user.
})
.register('app);
# GET   /user/hogehoge    -> 404 Not Found
# POST  /account/fugafuga -> 404 Not Found
# GET   /user/initialize  -> 404 Not Found
# GET   /user/list        -> 200 OK

##Runing tests

mocha test/router.js

##License MIT

Keywords

express

FAQs

Package last updated on 16 Jul 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts