Node.js Hot Rod Client: Getting Started

What You Will Learn

How to connect a Node.js Hot Rod client to an Infinispan Server and perform basic cache operations: put, get, and print values.

Prerequisites

  • Node.js

  • An Infinispan Server running on 127.0.0.1:11222

Step 1: Install Dependencies

npm install

This installs the infinispan Hot Rod client package.

Step 2: Connect and Perform Cache Operations

Create a client with authentication and connect to the server:

var infinispan = require('infinispan');

var connected = infinispan.client(
  {port: 11222, host: '127.0.0.1'},
  {
    cacheName: 'my-cache',
    clientIntelligence: 'BASIC',
    authentication: {
      enabled: true,
      saslMechanism: 'DIGEST-MD5',
      userName: 'admin',
      password: 'password'
    }
  }
);

Then put and get a value:

connected.then(function(client) {
  client.put('key', 'value').then(function () {
    return client.get('key').then(function (value) {
      console.log('key = ' + value);
    });
  }).finally(function() {
    return client.disconnect();
  });
});

Step 3: Run the Tutorial

npm start

You should see output like:

Connected
key = value
Disconnected