boot.js
This file
Path
examples/route-loading/boot.js
26 lines · 884 bytes · JavaScript
Last changed by
Not known.
History of this fileTake it
The walk stopped after 200 commits: lines older than f98c112 point at it.
Added app.render() local precedence testTj Holowaychukbefore adoptionf98c112
lines 1–26why, one step back12/**3 * Module dependencies.4 */56var vm = require('vm')7 , fs = require('fs');89module.exports = function(app, db){10 var dir = __dirname + '/routes';11 // grab a list of our route files12 fs.readdirSync(dir).forEach(function(file){13 var str = fs.readFileSync(dir + '/' + file, 'utf8');14 // inject some pseudo globals by evaluating15 // the file with vm.runInNewContext()16 // instead of loading it with require(). require's17 // internals use similar, so dont be afraid of "boot time".18 var context = { app: app, db: db };19 // we have to merge the globals for console, process etc20 for (var key in global) context[key] = global[key];21 // note that this is essentially no different than ... just using22 // global variables, though it's only YOUR code that could influence23 // them, which is a bonus.24 vm.runInNewContext(str, context, file);25 });26};