The following shows module APIs available for each platform.
| Linux (Ubuntu) |
Raspbian (Raspberry Pi) |
NuttX (STM32F4-Discovery) |
TizenRT (Artik053) |
|
|---|---|---|---|---|
| require | O | O | O | O |
The require function is always available there is no need to import module explicitly.
id{string} Module name to be loaded.
Loads the module named id.
Example
var assert = require('assert');
assert.equal(2, 2);Loading a module
If a native module named id exists, load it and return.
(Native module: which module came from the IoT.js itself)
require function searches for modules in the following order:
- Current working directory.
iotjs_modulesfolder under current working directory.$HOME/iotjs_modules$IOTJS_PATH/iotjs_modules
For each directory in search paths above:
- If a file
idexists, load it and return. - If a file
id.jsexists, load it and retun. - If a directory
idexists, module system consider the directory as a package:- If
id/package.jsoncontains main property, load the file named main property. - If
id/package.jsonexists, but neither the main property nor the file named main property exist, loadindex.js.
- If