Last active
March 22, 2018 19:34
-
-
Save areichman/19f47fee94252766b829ed713d5a1aed to your computer and use it in GitHub Desktop.
Parse a raw JS file as a Node.js module
This file contains hidden or 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
request('/foo.js') | |
.then((body) => { | |
const bodyExported = body + 'module.exports = foo;'; | |
const Module = module.constructor; | |
const m = new Module(); | |
m._compile(bodyExported, ''); | |
console.log(m.exports); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment