Access session info inside a separated module nodejs

I have the app.js with

var express = require('express')
  , routes = require('./routes')
  , MemoryStore = new express.session.MemoryStore
  , app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.cookieParser('restservice'));
  app.use(express.session({store: MemoryStore, secret: '123456', key: 'sid', maxAge: 60000 }));
  app.use(routes);  
  app.use(app.router);
});

the routes/index.js

var express = require('express')
  , tools = require('./../functions')
  , app = module.exports = express();

app.get('/user/:id',tools.isAdmin,function(req,res){
    console.log('isadmin');
});

and the function.js

module.exports = {
  isAdmin: function (res,req,next) {
    if (req.session.level >= 16)
        next();
    else {
        res.json({result:-1});
    }
  }
};

So my problem is when I access http://myadmin.com/user/3 I get an error of req.session undefined

How can I from the point of functions.js view get access to the session information?

app.js and index.js are creating two different apps, two different instances of express - two different servers.

Since you aren't requiring one from the other (index doesn't require app, and app doesn't require index), when you run one, only that one is running. If you run node app only app.js runs, and if you run node index only index.js runs.

You should probably look at the basic express app examples included in express's github repository:

https://github.com/visionmedia/express/tree/master/examples/mvc

The problem was in this line

isAdmin: function (res,req,next) {

for some reason I switched the res with the req. With

isAdmin: function (req,res,next) {

now I can get the session info.