sprouter

0.0.1 • Public • Published

SpRouter

Simple dynamic routing for expressjs can help you create any type of routing with ability editing routings and handlers in real time !

Installation

via npm:

$ npm install sprouter

Using

After installation SpRouter can be created with constructor:

Constructor:
    SpRouter(express_app, {path: String, auto: Boolean, watch: Boolean});

Example

...
var SpRouter = require('sprouter');
var Router = new SpRouter(app, {path: './routes', auto: true, watch: true});
...

Where app is a instance of express

var app = express();

{path: './routes', auto: true, watch: true}

path - Path to the directory with routing files

auto - Autorun routing default true

watch - Watch change of routing and rebuild route path default true

Routing structure

Directory structure
/routers
    |-index.js
var router = {

    base: '/',

    routes:{
        'get':{
            '': 'index', //default route
            'hello/:params': 'hello'
        },
        'post':{
            'signin/': 'signin'
        }
    },

    index: function(req,res){
        res.send("Welcome SpRouter !");
    },

    hello: function(req,res){
        res.send("Hello :" + req.params.params);
    },

    //post
    signin: function(req,res){
        //write code here
    }

};

module.exports = router;

Readme

Keywords

none

Package Sidebar

Install

npm i sprouter

Weekly Downloads

0

Version

0.0.1

License

BSD

Last publish

Collaborators

  • alexmarch