Let\'s say I have a file called app.js. Pretty simple:
var express = require(\'express\');
var app = express.createServer();
app.set(\'views\', __dirname + \
define({
"data": "XYZ"
});
var fs = require("fs");
var vm = require("vm");
function include(path, context) {
var code = fs.readFileSync(path, 'utf-8');
vm.runInContext(code, vm.createContext(context));
}
// Include file
var customContext = {
"define": function (data) {
console.log(data);
}
};
include('./fileToInclude.js', customContext);