Have a look at my config app.js
file! that should work to you as the variables will e available at that context.
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(connect.compress());
app.use(express.static(__dirname + "/public", { maxAge: 6000000 }));
app.use(express.favicon(__dirname + "/public/img/favicon.ico", { maxAge: 6000000 }));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({
secret: config.sessionSecret,
maxAge: new Date(Date.now() + (1000 * 60 * 15)),
store: new MongoStore({ url: config.database.connectionString })
}));
app.use(function(req, res, next){
console.log("\n~~~~~~~~~~~~~~~~~~~~~~~{ REQUEST }~~~~~~~~~~~~~~~~~~~~~~~".cyan);
res.locals.config = config;
res.locals.session = req.session;
res.locals.utils = viewUtils;
res.locals.greet = function(){
//req and res are available here!
return "hey there " + req.user.name;
};
next();
});
app.use(app.router);
});
writing helpers that I can use inside my jade templates
? – Mudpack