Select the module to load by its path. Note that by default, the search
context for the
path is the source file itself, not its parent like on
POSIX systems. So, if file
/foo.js is executing and you want to load
/bar.js, than you have to require
If the path starts with a file name, that is, not with any of
../, it is said to be a global module path. Such global paths are looked
/sys/packages. For example,
For compatibility reasons, there is a way to require files in POSIX mode
by setting the source file’s
posix int32 attribute to
1. Then, if file
/foo.js is executing and you want to load the module
would have to require
File extensions must be explicitly provided. If
/foo.js is executing, and
you want to load
/foo.js/bar.js, then require it by
./bar.js, not just
Requiring a module allows you to build libraries (modules) and reuse them across your applications. The CommonJS 1.1 specification is implemented.
The following variables are injected in the required executing context:
module exports require
response are not
available. The callee must pass them in for use.
Modules MUST NOT define variables on the global scope.
var when defining them.)
Publishing a function directly via module.exports.
Publishing a function via returning it.
Publish multiple functions.
Nested require() with absolute path.
Nested require() with relative path.
Example for using module.id.
Example for using module.file.
Require fails: can not find module.
Require fails: unexpected file type.
Required code does not have access to response object.
Required code does not have access to request object.
Required code does not have access to f object.
Required code does not have access to context object.
Required code does not have access to source object.
Requiring a global module.