custom module: expose global object that persists accross module reloads.

This commit is contained in:
jean-emmanuel 2022-11-29 08:36:09 +01:00
parent 9197eea0ac
commit 6ef1d412f9
3 changed files with 10 additions and 2 deletions

View file

@ -137,6 +137,7 @@ This function can be used to load native node modules or locally installed modul
- `__dirname`
- `__filename`
- `process`
- `global`
----
@ -145,6 +146,8 @@ This function can be used to load native node modules or locally installed modul
Custom modules (including submodules loaded with `require()`) are reloaded automatically when they are modified. Upon reload, timers (`setTimeout` and `setInterval`) and event listeners (added to the  `app` object) are reset.
The `global` object persists accross reloads.
??? "Reloading native modules"
When using modules loaded with `nativeRequire()`, you may need to tell the custom module how to unload some components to allow reloading using the `module.exports.unload` definition. For example, if a port is bound using the `http` module, you'll need to unbind it otherwise the custom module will fail to bind it again when reloading: