The argument of require(...) in node.js is a filename. If I had a module source code in a string code, could I somehow call require(code) and load functions from that string?
The argument of require(…) in node.js is a filename. If I had a module
Share
A work around could be to write the module source code to a temporary file
./tmp-file.jsand thenrequire('./tmp-file'), and then remove the file.This is probably not optimal because you would either have to block and write the file synchronously, or put everything requiring that module in the callback to the async write.
A working example for async file write (gist – also includes sync file write):
Results in: