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

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -