Reputation: 4683
I mean if I want to do something in browser, such as call eval, I can do this:
window['eval']();
As in "calling eval with string".
But in Node there is no window. There is global
, but that does not have require in it.
What contains require in node, so that I can do:
???['require']();
I tried this[require]
in global scope and global['require']
and I also tried finding the require function parent with require.prototype
and require.constructor
but without luck.
Edit:
require
does indeed exist somewhere, because by just writing require('vm')
for example, it works.
The Node.js source contains NativeModule.require
and nativeModule
references, but NativeModule
is not defined when I try to use it.
Upvotes: 2
Views: 274
Reputation: 4683
module['require']
worked for me in the end. I am using Node v0.10.35 in case that matters.
Two other globals to look the require function for could be global['require']
or perhaps even process['require']
?
Upvotes: 1
Reputation: 5317
global['require']
exists in Node 0.10+, so you have made a mistake or you are using some very ancient version of Node.
Upvotes: 1