Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express - Passing data to all routes

Hi is there a 'express' specific way to make some global app data available to all my routes? Or is it a case of just using an module.exports statement?

Any pointers more than welcome. Node noob - btw

like image 799
Chin Avatar asked Nov 18 '11 01:11

Chin


1 Answers

You can set a global object that is also available in your layout

app.js

app.configure(function(){
  app.set('view options', {pageTitle: ''});
});

app.get('/',function(request, response){
  response.app.settings['view options'].pageTitle = 'Hello World';
  response.render('home');
});

layout.jade

!!!
html
  head
    title= pageTitle
  body!= body
like image 182
Pastor Bones Avatar answered Sep 26 '22 20:09

Pastor Bones