Use Node.js in your end devices(QQ: 796448809)
Markdown Example
is added to help understanding, and you can ignore it when writing the actual document."Module"
, "Module Function"
, "Class"
, "Constructor"
, "Properties"
, "Static Function"
, "Prototype Functions"
, and "Events"
. If the content does not exist, it can be omitted.Module Functions
are what you can directly invoke without an instance of a certain Class. E.g) net.connect.experimental
module, it’s required to explicitly indicate that the features are experimental. Please put the caution below to the beginning of the document.
:exclamation: This document describes an experimental feature and considerations. Please be aware that every experimental feature may change, be broken, or be removed in the future without any notice.
The following shows {Your_module_name}
module APIs available for each platform.
Linux (Ubuntu) |
Raspbian (Raspberry Pi) |
NuttX (STM32F4-Discovery) |
|
---|---|---|---|
{class_name}.{functionName1} | O | O | O |
{class_name}.{functionName2} | O | O | O |
{class_name}.{functionName3} | O | O | O |
Uppercase letter
.# Timer
The timer module exposes a global API for scheduling functions to be called at some future period of time.
Because the timer functions are globals, there is no need to call require('timers') to use the API.
{argument_name}
{more information} Default: {defalut_value}
Returns: {more information}
lowercase letter
.Example
Write a sample usage for this API if needed.
### net.connect(port[, host][, connectListener])
* `port` {number} Port the client should connect to.
* `host` {string} Host the client should connect to. **Default:** `localhost`.
* `connectListener` {Function} Listener for the `'connect'` event.
* Returns {net.Socket}.
Creates a new `net.Socket` and automatically connects to the supplied `port` and `host`.
If host is omitted, `localhost` will be assumed.
The `connectListener` is automatically registered as a `'connect'` event listener.
Uppercase letter
.While you are writing this description, if you need to write down module / class / function / event name, arguments, or type which you already mentioned, then enclose the keyword in single-quotation. This rule applies to other items as well.
E.g) The given callback
is called every delay
milliseconds. If it’s not a function, a TypeError
will be thrown.
{argument_name}
{more information} Default: {defalut_value}
Notice that every argument name of API and defalut value are in a single-quote.
Example
Write a sample usage for this API if needed.
# Class: Buffer
Buffer class is a global type with various constructors and accessors.
IoT.js provides Buffer to manipulate binary data. Currently buffer has a pure
ES5 compatible implementation, but this might be reworked to use `UInt8Array` in the future.
### new Buffer(size)
* `size` {integer} Size of the new buffer.
Creates a new buffer of `size` bytes and initialize its data to zero.
{argument_name}
{more information} Default: {defalut_value}
Returns: {more information}
Uppercase letter
.Example
Write a sample usage for this API if needed.
### Buffer.byteLength(str, encoding)
* `str` {string} Source string.
* `encoding` {string} String encoding.
* Returns: {integer} Byte length of source string.
Returns the byte length of a buffer representing the value
of the string argument encoded with encoding. The effect is
the same as:
```js
return new Buffer(str, encoding).length;
lowercase letter
.Example
Write a sample usage for this API if needed.
### buf.length
* {integer}
Returns the capacity of the buffer in bytes. Note: when
the buffer is converted to another type (e.g. `String`) the
length of the converted value might be different from
this value.
**Example**
```js
var Buffer = require('buffer');
var buffer = new Buffer([0xc8, 0x80])
console.log(buffer.length); // prints 2
var str = buffer.toString();
console.log(str.length); // prints 1
{argument_name}
{more information} Default: {defalut_value}
Returns: {more information}
lowercase letter
.Example
Write a sample usage for this API if needed.
### emitter.on(event, listener)
* `event` {string} The name of the event.
* `listener` {Function} The callback function.
* `args` {any}.
* Returns `emitter` {events.EventEmitter}.
Adds the `listener` callback function to the end of the listener's list for the given `event`. No checks are made to see if the `listener` has already been added.
In case of multiple calls the `listener` will be added and called multiple times.
**Example**
```js
var EventEmitter = require('events').EventEmitter;
var emitter = new EventEmitter();
emitter.on('event', function() {
console.log('emit event');
});
emitter.emit('event');
{callback_name}
{argument1}
{more information}### Event: 'lookup'
* `callback` {Function}
* `err` {Error}
* `address` {string}
* `family` {string|null}
Emitted after resolving hostname.
err {Error}
above is started with 2 spaces
indentation since it’s given to callback
as parameters, not lookup
event.