class Module
interface Module
The register
method is a non-functional stub.
The register
method is a non-functional stub.
Properties #
The module.exports
object is created by the Module
system. Sometimes this is
not acceptable; many want their module to be an instance of some class. To do
this, assign the desired export object to module.exports
.
#isPreloading: boolean
true
if the module is running during the Node.js preload
phase.
The module that first required this one, or null
if the current module is the
entry point of the current process, or undefined
if the module was loaded by
something that is not a CommonJS module (e.g. REPL or import
).
The directory name of the module. This is usually the same as the
path.dirname()
of the module.id
.
Methods #
namespace Module
The register
method is a non-functional stub.
Classes #
Functions #
path
is the resolved path for the file for which a corresponding source map
should be fetched.
Flush the module compile cache accumulated from modules already loaded in the current Node.js instance to disk. This returns after all the flushing file system operations come to an end, no matter they succeed or not. If there are any errors, this will fail silently, since compile cache misses should not interfere with the actual operation of the application.
Register a module that exports hooks that customize Node.js module resolution and loading behavior. See Customization hooks.
module.stripTypeScriptTypes()
removes type annotations from TypeScript code. It
can be used to strip type annotations from TypeScript code before running it
with vm.runInContext()
or vm.compileFunction()
.
By default, it will throw an error if the code contains TypeScript features
that require transformation such as Enums
,
see type-stripping for more information.
When mode is 'transform'
, it also transforms TypeScript features to JavaScript,
see transform TypeScript features for more information.
When mode is 'strip'
, source maps are not generated, because locations are preserved.
If sourceMap
is provided, when mode is 'strip'
, an error will be thrown.
The module.syncBuiltinESMExports()
method updates all the live bindings for
builtin ES Modules
to match the properties of the CommonJS
exports. It
does not add or remove exported names from the ES Modules
.
Interfaces #
Namespaces #
Type Aliases #
The initialize
hook provides a way to define a custom function that runs in
the hooks thread when the hooks module is initialized. Initialization happens
when the hooks module is registered via register.
The load
hook provides a way to define a custom method of determining how a
URL should be interpreted, retrieved, and parsed. It is also in charge of
validating the import attributes.
The resolve
hook chain is responsible for telling Node.js where to find and
how to cache a given import
statement or expression, or require
call. It can
optionally return a format (such as 'module'
) as a hint to the load
hook. If
a format is specified, the load
hook is ultimately responsible for providing
the final format
value (and it is free to ignore the hint provided by
resolve
); if resolve
provides a format
, a custom load
hook is required
even if only to pass the value to the Node.js default load
hook.
Variables #
A list of the names of all modules provided by Node.js. Can be used to verify if a module is maintained by a third party or not.