Repository navigation
03. Module parameters
######INITIALISATION PARAMETERS
Many browser-side requirers provide an environment with only require, module, exports.
However, for many Node.js modules to work, they also require access to __filename and __dirname.
NodalRequire will resolve the full address and then put the file name in __filename and the path leading up to the file name in __dirname. Some points to note about the canonical forms:
-
__filenameincludes the.jsextension (but does not include an search tag). -
__dirnamedoes not include a final/. - These are all lower case. Unlike node.js, currently different modules of different casing resolve to the same module. This is because the web is largely case-insensitive and building in case sensitivity at this stage may make things harder rather than easier, but this may change later if different registry differentiation is required.
-
module.address=__filenamecurrently, but this may change later if different aliasing is required.
######MODULE PROPERTIES
The module object contains the following properties:
-
__dirname:StringThe registered address of the folder containing the module's (lower case). -
__filename:StringAlias for address. -
address:StringThe registered address of this module (lower case). -
definition:StringThe bare text of the module's definition, without the surrounding functional decoration that is added to form the constructor. -
error?:ErrorAny error loading the module. -
exports:ObjectThe exports of the module. This is used for 'this' in binding. -
constructor:ModuleConstructorA function used to form the module closure: constructor = new Function(..., definition). -
isInitialised:BooleanWhen the all of module's requirements are loaded, it can be initialised upon first call. -
type:"node"|"local"|"dynamic""node": sourced from a node_module folder along the caller's lineage; "local": sourced via a file path ('./'. '../', 'http://', etc); "dynamic": defined dynamically.
These are likely to increase if required.
They can be accessed directly from within a module via module[].
######INCOMPATIBILITIES WITH NODE.JS MODULE PROPERTIES
A Node.js module has the following interface:
interface NodeModule {
exports:Object;
require:(id:String)=>any;
id:String;
filename:String;
loaded:Boolean;
parent:Object;
children:Object[];
}
TODO: Currently, these inconsistencies may be a source of difficulty for some modules. They are planned to be properly abstracted.