Search code examples
node.jsexpressmongoosedust.js

Dustjs with express, set of data available globally on all views/routes


I have a set of data that I want globally available in all my views.

I'm aware that I can do something like:

'use strict';

var ShowsModel = require('../../models/shows');

module.exports = function (router) {
    var model = new ShowsModel();
    router.get('/', function (req, res) {
         model.find({}, function(sent, recieved){
             res.render('shows/index', { shows: recieved });
         });

    });

};

But lets say I want, some model globally available for all the views, is there a way to do it without me adding it to every render method call for every view?


Solution

  • You can do app.set("data", obj), and then call it from the views using settings.data.