Version0 /
ModuleSpecificationModules are formatted according to the CommonJS Module standard. This standard specifies that a module may be contained within a single JavaScript file with name module-name.js or in a directory named module-name containing a package.json file, which gives an object that defines properties of the module. The JavaScript file or files in a module may define top-level variables, but these will be local to the module and not visible to the accessor script. A module makes its components available to the accessor script by defining fields of its exports field. For example, if the exports.moduleFunction = function() {...}; then the accessor script can invoke the module's function as follows: var module = require('@accessors/module-name'); module.moduleFunction(); Alternatively, the module JavaScript file can explicitly define the exports object as follows: var myFunction = function() {...}; module.exports = { myFunction : myFunction }; Module NamingIn addition, modules follow the Node Package Manager (npm) package name specification where package names are lower case and hyphenated. Host-specific modules should be in the var module = require('@accessors/web-socket-client'); The host-specific implementation of require may remap the scope and package name. |