Specifically, if require.main is not defined, the variable mainDir will be set to process.cwd().
This will prevent a fatal error, and instead allow a basic level of REPL support.
There are some limitations that might not be obvious: changes to the process working directory will not be tracked, and the node-hotload module will sometimes fail silently if one saves a unsyntactic version of the code being watched; the node-hotload module then requires reloading from cache.
Specifically, if
require.main
is not defined, the variablemainDir
will be set toprocess.cwd()
.This will prevent a fatal error, and instead allow a basic level of REPL support.
There are some limitations that might not be obvious: changes to the process working directory will not be tracked, and the node-hotload module will sometimes fail silently if one saves a unsyntactic version of the code being watched; the node-hotload module then requires reloading from cache.