Load node.js module from string in memory -
how require() file if had file's contents string in memory, without writing out disk? here's example:
// load file string var strfilecontents = fs.readfilesync( "./myunalteredmodule.js", 'utf8' ); // stuff files contents strfilecontents[532] = '6'; // load node module (how this?) var loadedmodule = require( domagic(strfilecontents) );
function requirefromstring(src, filename) { var module = module.constructor; var m = new module(); m._compile(src, filename); return m.exports; } console.log(requirefromstring('module.exports = { test: 1}'));
look @ _compile, _extensions , _load in module.js
Comments
Post a Comment