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

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.

  1. Use npm (Node Package Manager) tool in 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.

  2. Create a node_modules directory in your service's root directory. 

  3. 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');
You cannot use modules that include C/C++ addons. You must use modules implemented with JavaScript only.

 

Navigation