era

express-routing-app

Helper for routing express applications

Showing:

Popularity

Downloads/wk

1

GitHub Stars

1

Maintenance

Last Commit

5yrs ago

Contributors

1

Package

Dependencies

0

Size (min+gzip)

0.5KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Express Routing

Readme

Express Routing App

Helper for routing Express applications.

Install

This module require node >= 6.5.0 because is written with the last ECMAScript 6 features, so firstly check your version.

$ npm install express-routing-app --save

Example

/index.js
const express = require('express');
const app = express();
const RoutingApp = require('express-routing-app');

const routingApp = new RoutingApp({
    root: __dirname,
    models: {
        User: ...
    }
});

app.use(routingApp.Router(__dirname+'/router/index', { message: 'Hello' }));

app.listen(3000);
/router/index.js
module.exports = function(router, routingApp, args){

    router.get('/', function(req, res, next){
        res.render('index', { message: args.message });
    });

    router.use('/user', routingApp.Route(__dirname+'/user'));
}
/router/user.js
module.exports = function(router, routingApp){

    const {User} = routingApp.models;

    router.get('/', function(req, res, next){
        User.find({}, function(err, users){
            res.render('users', { users: users });
        });
    });
}

How work

Instantiate the class passing all variables, methods or other stuff to constructor:

const RoutingApp = require('express-routing-app');
const routingApp = new RoutingApp({
    root: __dirname,
    myFun: function(){ ... }
    models: {
        User: ...
    }
});

now you can call Router method passing the absolute path of the file that defining your router, optionally you can pass also your parameters.
The method Router return a new express router

app.use(routingApp.Router(absoluteFilePath, ...yourParameters));

the passed file can export an express router or export a function with the follow format

module.exports = function (router, routingApp, ...yourParameters){
    ...
}
  • router is the new express router, use it for implement your logic
  • routingApp is the routingApp instance that call this file, use it for access to all your application stuff or call nested Router
  • yourParameters spread parameters that you pass when call Router

Credits

License

MIT

Copyright (c) 2016 Sergio Donati

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Tutorials

No tutorials found
Add a tutorial