Created
November 25, 2012 18:36
-
-
Save paulbatum/4144724 to your computer and use it in GitHub Desktop.
Magic buckets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vm = require('vm'); | |
var fs = require('fs'); | |
var logger = { | |
log: function() { | |
console.log('<foo>'); | |
console.log.apply(null, arguments); | |
console.log('</foo>'); | |
} | |
} | |
var context = vm.createContext({ console: logger, require: require}); | |
var script = fs.readFileSync('script.js', 'utf8'); | |
vm.runInContext(script, context); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.writeToLog = function() { | |
console.log("this is from a module"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<foo> | |
this is from the script | |
</foo> | |
this is from a module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var module = require('./module.js'); | |
console.log("this is from the script"); | |
module.writeToLog(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment