1

In the node js module system, to use require(), one must have the file path of the module as such —

const foo = require('/path/to/bar');
foo();

However, say I have a javascript file in memory, whose contents I know, but not the path. How can i simulate —

const foo = customRequire(/* contents of the file as string */)
foo();

Is there a better way than to just eval() the string ?

Shubham Kanodia
  • 6,036
  • 3
  • 32
  • 46

0 Answers0