NodeJS vm.runInThisContext() and lack of __filename
- by rFactor
Whenever I run vm.runInThisContext(code, filename), the ran code reports __filename and __dirname as undefined.
This also leads to the situation that any fs.readFile and such calls will not work with relative paths. For example this does not work: fs.readFile('../file', fn); because it does not know where to relate the path to.
Specifying the filename as /home/full/path/to/file.js for vm.runInThisContext function does not seem to matter at all.
How can I make Node to understand the path to the file?