Using Node.js Module
Supported Node.js Version
webOS TV supports the different versions of Node.js core modules depending on the webOS version as below.
webOS Version |
Node.js Version |
---|---|
webOS 1.x |
v0.10.15 |
webOS 2.x |
v0.10.25 |
webOS 3.x |
v0.12.2 |
webOS 4.x |
v0.12.2 |
webOS 5.0 |
v8.12.0 |
webOS 6.0 |
v12.14.1 |
Using Node.js Core Modules
To use the Node.js core module, add the module with a top-level identifier to your service as the following code.
var Service = require('webos-service'); var md5 = require('md5'); var service = new Service("com.yourdomain.helloworldservice.service"); service.register("hello", function(message) { message.respond({ data: "Hello, " + md5(message.payload.name) + "!" }); });
Using Third-party Modules
There are many third-party modules for Node.js. To use the third-party modules, follow the next steps.
-
Use NPM (Node Package Manager) tool on your computer to install the third-party module. The module is installed in the node_modules directory under the node.js installation folder.
See Node Packaged Modules (NPM) for the search and installation of these modules. -
Create a node_modules directory in your service's root directory.
-
Copy modules from the node_modules directory under the node.js folder to the node_modules directory under your service's root directory.
Now, add the third-party module to your service as the following code. The node will find the module from the node_modules directory first.
var md = require('md5');