NodeJS vm.runInThisContext() and lack of __filename

Posted by rFactor on Stack Overflow See other posts from Stack Overflow or by rFactor
Published on 2011-06-28T12:52:36Z Indexed on 2011/06/28 16:22 UTC
Read the original article Hit count: 284

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about node.js