Skip to content

Instantly share code, notes, and snippets.

@areichman
Last active March 22, 2018 19:34
Show Gist options
  • Save areichman/19f47fee94252766b829ed713d5a1aed to your computer and use it in GitHub Desktop.
Save areichman/19f47fee94252766b829ed713d5a1aed to your computer and use it in GitHub Desktop.
Parse a raw JS file as a Node.js module
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