Guy Messika Guy Messika - 3 months ago 48
Node.js Question

Load node modules from virtual file system

I'm trying to load some node modules from a virtual file system
but I can't make it work

var request = require('request')
, AdmZip = require('adm-zip')
, fs = require('fs')
, unionfs = require('unionfs')
, memfs = require('memfs')
, mem = new memfs.Volume
, data = []


var req = request({
method: 'GET',
uri: '****',
headers: {
"encoding": "binary"

req.on('data', function(chunk) {
}).on('end', function() {
var binary = Buffer.concat(data)
mem.mountSync('./', {
"": binary

var zip = new AdmZip("./")
var files = {}
zip.getEntries().forEach(function(entry) {
if (entry.isDirectory)
files[entry.entryName] = entry.getData()
mem.mountSync('./node_modules', files)

//need to get these modules dynamically
var async = require("async")

The error I get is: Error: Cannot find module 'async'

now I was trying to use this module to add my virtual path but it only gets physical paths.

Can anybody help me with this pleas?

Don't worry about security I'm going to use encryption with this.


The author of unionfs writes that the require does not work in new versions of the node.js:

// NOTE: This does not work in new Node.js
// Now you can also do:
// require('/usr/mem/dir/hello.js');
// Hello world!
// require('/project/hello.js');
// Hello world!