Ignite Quick Start Guide for Node.JS | Ignite Documentation
Edit

Ignite Quick Start Guide for Node.JS

This chapter explains system requirements for running Ignite, how to install Ignite, start a cluster and run a simple Hello World example using a thin client for Node.js.

Thin Client is a lightweight Ignite connection mode. It does not participate in cluster, never holds any data, or performs computations. All it does is establish a socket connection to an individual Ignite node and perform all operations through that node.

Prerequisites

Ignite was tested on:

JDK

Oracle JDK 8, 11 or 17 Open JDK 8, 11 or 17, IBM JDK 8, 11 or 17

OS

Linux (any flavor), Mac OSX (10.6 and up), Windows (XP and up), Windows Server (2008 and up), Oracle Solaris

ISA

x86, x64, SPARC, PowerPC

Network

No restrictions (10G recommended)

and:

Node.js

Version 8 or higher is required. Either download the Node.js pre-built binary for the target platform, or install Node.js via package manager.

Installing Ignite

To get started with the Apache Ignite binary distribution:

  1. Download the Ignite binary as a zip archive.

  2. Unzip the zip archive into the installation folder in your system.

  3. (Optional) Enable required modules.

  4. (Optional) Set the IGNITE_HOME environment variable or Windows PATH to point to the installation folder and make sure there is no trailing / (or \ for Windows) in the path.

Once that’s done, execute the following command to install the Node.js Thin Client package:

npm install -g apache-ignite-client

Starting a Node

Before connecting to Ignite from Node.JS thin client, you must start at least one cluster node.

You can start a node from the command line using the default configuration or by passing a custom configuration file. You can start as many nodes as you like and they will all automatically discover each other.

Navigate into the bin folder of the Ignite installation directory from the command shell. Your command might look like this:

cd {IGNITE_HOME}/bin/
cd {IGNITE_HOME}\bin\

Start a node with a custom configuration file that is passed as a parameter to ignite.sh|bat like this:

./ignite.sh ../examples/config/example-ignite.xml
ignite.bat ..\examples\config\example-ignite.xml

You will see output similar to this:

[08:53:45] Ignite node started OK (id=7b30bc8e)
[08:53:45] Topology snapshot [ver=1, locNode=7b30bc8e, servers=1, clients=0, state=ACTIVE, CPUs=4, offheap=1.6GB, heap=2.0GB]

Open another tab from your command shell and run the same command again:

./ignite.sh ../examples/config/example-ignite.xml
ignite.bat ..\examples\config\example-ignite.xml

Check the Topology snapshot line in the output. Now you have a cluster of two server nodes with more CPUs and RAM available cluster-wide:

[08:54:34] Ignite node started OK (id=3a30b7a4)
[08:54:34] Topology snapshot [ver=2, locNode=3a30b7a4, servers=2, clients=0, state=ACTIVE, CPUs=4, offheap=3.2GB, heap=4.0GB]
Note
By default, ignite.sh|bat starts a node with the default configuration file: config/default-config.xml.

Running Your First Application

Once the cluster is started, you can use the Ignite Node.js thin client to perform cache operations. Your Ignite installation includes several ready-to-run Node.JS examples in the {client_dir}/examples directory. For example,

cd {client_dir}/examples
node CachePutGetExample.js

Assuming that the server node is running locally, and that you have completed all of the pre-requisites listed above, here is a very simple HelloWorld example that puts and gets values from the cache. If you followed the instructions above, and if you place this hello world example in your examples folder, it should work.

const IgniteClient = require('apache-ignite-client');
const IgniteClientConfiguration = IgniteClient.IgniteClientConfiguration;
const ObjectType = IgniteClient.ObjectType;
const CacheEntry = IgniteClient.CacheEntry;

async function performCacheKeyValueOperations() {
    const igniteClient = new IgniteClient();
    try {
        await igniteClient.connect(new IgniteClientConfiguration('127.0.0.1:10800'));
        const cache = (await igniteClient.getOrCreateCache('myCache')).
            setKeyType(ObjectType.PRIMITIVE_TYPE.INTEGER);
        // put and get value
        await cache.put(1, 'Hello World');
        const value = await cache.get(1);
        console.log(value);

    }
    catch (err) {
        console.log(err.message);
    }
    finally {
        igniteClient.disconnect();
    }
}

performCacheKeyValueOperations();

Next Steps

From here, you may want to: