A friend asked an interesting question, and I tried several things, but to no avail, is there any way to override the Node JS module?
For example, I want to override the readFile function to use the S3 bucket instead of the file system. I.e:
var fs = require('fs'); fs.readFile('my_text_file.txt', ...);
Actually something like this works
FileSystem.readFile = function () {
I tried the prototype, but it seems that they installed their own modules without the __proto__ object, they do not have the .constructor property, which means something to anyone.
I was thinking about using Nodes VM , but this is too strict, since I want the user to be able to install modules through npm and use them.
The closest I came to is to create a new module (since I canβt put a file named fs.js in my node_modules folder and require it, it just ignores it) and just sets the values ββfrom fs to what I want, but this not quite right, I want the user to use require('fs') and use my custom function.
Is this possible without compiling my own version of Node JS?
source share