Skip to content

Instantly share code, notes, and snippets.

@scripting
Last active April 20, 2020 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scripting/3e5454f2b7a10029dfc301d7deabb576 to your computer and use it in GitHub Desktop.
Save scripting/3e5454f2b7a10029dfc301d7deabb576 to your computer and use it in GitHub Desktop.
exports.helloWorld = function () {
return ("hello world");
}
{
"name": "requirefromstringtest",
"description": "Test requirefromstring package.",
"author": "Dave Winer <dave@scripting.com>",
"version": "0.4.0",
"scripts": {
"start": "node test.js"
},
"dependencies" : {
"require-from-string": "*"
},
"license": "MIT",
"engines": {
"node": "*"
}
}
const fs = require ("fs");
const requireFromString = require ("require-from-string");
fs.readFile ("mymodule.js", function (err, moduletext) {
var val = requireFromString (moduletext.toString ()).helloWorld ();
console.log (val);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment