Chapter 5. Cordova

5.1. npm

npm is the package manager for distributing JavaScript code. It is used to install the RHMAP JavaScript SDK for developing Cordova apps.

5.1.1. Installing Node.js and npm

You must have Node.js installed on your system to use npm. It is recommended that you install NodeJS version 4.x or later, which includes npm version 2.x by default.

5.1.1.1. Install Node.js Using a Package Manager

To install Node.js using your system package manager, follow the instructions appropriate for your system on the Node.js site

To check the version of npm you are currently using, execute the following command:

sudo npm -v

5.1.2. Installing Node.js and npm on Red Hat Enterprise Linux

To install NodeJS on systems running RHEL, you must obtain the installation files from the Red Hat Software Collections. Installing NodeJS requires a subscription to the Red Hat Subscription Manager.

To install NodeJS on RHEL, follow the guide on the Red Hat Developers Portal.

5.2. Get Started

The RHMAP JavaScript SDK lets you use RHMAP APIs in Cordova apps, which are developed primarily using web technology — HTML, JS, CSS — while still allowing access to many device capabilities.

The underlying native project and Cordova libraries are exposed to the developer. This allows for full customisation of the application, including Cordova Plugins and third-party libraries. Typically, the amount of time spent writing or modifying native code for Cordova apps is relatively small & requires only a small subset of a development team to have experience with native code. This small subset can handle the native code and expose any additional plugins or SDKs through a JavaScript API using the Cordova plugin architecture.

See the official Cordova website for more information on Cordova.

5.2.1. New App

Download the sample app to get started with a new Cordova App which has the RHMAP JavaScript SDK already included.

5.2.2. Existing App

Note

fh-js-sdk is distributed using npm. To be able to complete the steps below, you must install npm.

  1. In the root folder of your app, open the package.json file and add the latest version of fh-js-sdk onto the list of dependencies:

      "dependencies": {
        "fh-js-sdk": "^2.17.5",
      }
  2. In the root folder of your app, execute the following command to install the SDK using npm:

    sudo npm install fh-js-sdk

    This installs the SDK version specified in the dependencies in the package.json file

  3. Add the following code to your index.html file:

    <head>
      <script src="feedhenry.js" type="text/javascript"></script>
    </head>

5.2.3. Setup

Finally, you need to define properties which allow your app to communicate with RHMAP servers. Create a new file in the same directory as the SDK file, called fhconfig.json, with the following contents, replacing the references in brackets with values from your project:

{
  "host": "<RHMAP Core host>",
  "projectid": "<Project ID>",
  "connectiontag": "<Connection tag>",
  "appid": "<Client App ID>",
  "appkey": "<Client App API key>"
}

See Projects - Connections for more information on connections between Client Apps and Cloud Apps.

5.3. API Documentation

  • API Docs - documentation for all Client APIs
  • JS SDK - JavaScript SDK