Version1 /
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. In 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-modules/web-socket-client'); The host-specific implementation of require may remap the scope and package name. For example, the Node Host module definitions in the 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 that requires a module that is not one of the Built-In JavaScript Modules can invoke the module's function as follows: var module = require('@accessors-modules/module-name'); module.moduleFunction(); Alternatively, the module JavaScript file can explicitly define the exports object as follows: var myFunction = function() {...}; module.exports = { myFunction : myFunction }; The Some hosts, such as the Node Host can install packages at run time using a package manager such as NPM. See accessors/web/hosts/node/node_modules/@accessors-modules/serial/serial.js. See Require Notes -> npm.
|