node package manager
Painless code sharing. npm Orgs help your team discover, share, and reuse code. Create a free org »



Routes and functions loader

For example: we have two dirs in a root of our project


In /functions we have:


/functions/say.js code:

    // ATTENTION! Don't place your code outside export function, You'll not be able to connect with them, code from exports evaled in nodes VM, exedra passing other context into it 
    module.exports = function(){
      var fn = {};
      fn.hello = function(){
        return 'hello';

In /routes we have:

/routes/index.js /routes/index/foo.js

/routes/index.js code:

    module.export = function(){
      // We will use this, because it`s express-namespace 
      this.get('/bar', function(req, res, next){}); // == 

Now lets run our hello function from say.js

/routes/index/foo.js code:

    module.exports = function(){
      // Yeah, you could use app instead of this 
      app.get('/', function(req, res, next){ // == 
        res.send(fn.say.hello()); // calling funtcion hello from say.js 

Ok. Now we need entry point


    var express = require('express')
      , Exedra = require('exedra')
      , vs = { foo: 1, bar: 2 }; // This vars will be sended in context of each route/function 
    var app = = express.createServer(); // !!!WE NEED TO PASS app INTO vs 
    var exedra = new Exedra(vs);
    exedra.functions({ foo: 1 }).routes({ foo: 2 }); // We can extend context 

For more details see /examples/simple-project