Recent Changes - Search:

edit SideBar

ModuleSpecification

Modules 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 @accessors-modules/module-name.js file contains this:

   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 Naming

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 @accessors npm scope. An example of the correct way for an accessor to require a host-specific module is:

 var module = require('@accessors/web-socket-client');

The host-specific implementation of require may remap the scope and package name.


Back to accessor specification

Edit - History - Print - Recent Changes - Search
Page last modified on June 07, 2017, at 08:02 PM