Node.js Thin Client
How to install and use the GridGain 8 Node.js thin client: creating a client instance, connecting to a cluster, key-value operations, type mapping, scan and SQL queries, SSL/TLS, and authentication.
Prerequisites
Node.js version 8 or higher. Either download the Node.js pre-built binary for the target platform, or install Node.js via a package manager.
Once node and npm are installed, you can use one of the following installation options.
Installation
The Node.js thin client is shipped as an npm package and as a zip archive. Use any of the methods to install the client in your environment.
Using NPM
Use the following command to install the client from the NPM repository:
npm install -g @gridgain/thin-clientUsing ZIP Archive
The thin client can be installed from the zip archive available for download from the GridGain website:
Download the GridGain Node.js Thin Client archive.
Unpack the archive and navigate to the root folder.
Run the commands below to finish the installation.
npm link
npm link @gridgain/thin-clientCreating a Client Instance
The IgniteClient class provides the thin client API. You can obtain an instance of the client as follows:
The constructor accepts one optional parameter that represents a callback function, which is called every time the connection state changes (see below).
You can create as many IgniteClient instances as needed. All of them will work independently.
Connecting to Cluster
To connect the client to a cluster, use the IgniteClient.connect() method. It accepts an object of the IgniteClientConfiguration class that represents connection parameters. The connection parameters must contain a list of nodes (in the host:port format) that will be used for failover purposes.
The client has three connection states: CONNECTING, CONNECTED, DISCONNECTED. You can specify a callback function in the client configuration object, which will be called every time the connection state changes.
Interactions with the cluster are only possible in the CONNECTED state. If the client loses the connection, it automatically switches to the CONNECTING state and tries to re-connect using the failover mechanism. If it fails to reconnect to all the endpoints from the provided list, the client switches to the DISCONNECTED state.
You can call the disconnect() method to close the connection. This will switch the client to the DISCONNECTED state.
Partition Awareness
Partition awareness allows the thin client to send query requests directly to the node that owns the queried data.
Without partition awareness, an application that is connected to the cluster via a thin client executes all queries and operations via a single server node that acts as a proxy for the incoming requests. These operations are then re-routed to the node that stores the data that is being requested. This results in a bottleneck that could prevent the application from scaling linearly.

Notice how queries must pass through the proxy server node, where they are routed to the correct node.
With partition awareness in place, the thin client can directly route queries and operations to the primary nodes that own the data required for the queries. This eliminates the bottleneck, allowing the application to scale more easily.

To enable partition awareness, set the partitionAwareness configuration parameter to true as shown in the following code snippet:
Enabling Debug
Using Key-Value API
Getting Cache Instance
The key-value API is provided through an instance of a cache. The thin client provides several methods for obtaining a cache instance:
Get a cache by its name.
Create a cache with a specified name and optional cache configuration.
Get or create a cache, destroys a cache, etc.
You can obtain as many cache instances as needed - for the same or different caches - and work with all of them in parallel.
The following example shows how to get access to a cache by name and destroy its later:
Cache Configuration
When creating a new cache, you can provide an instance of the cache configuration.
Type Mapping Configuration
The node.js types do not always uniquely map to the java types, and in some cases you may want to explicitly specify the key and value types in the cache configuration. The client will use these types to convert the key and value objects between java/javascript data types when executing read/write cache operations.
If you don't specify the types, the client will use the Default Mapping. Here is an example of type mapping:
Data Types
The client supports type mapping between Ignite types and JavaScript types in two ways:
Explicit mapping
Default mapping
Explicit Mapping
A mapping occurs every time an application writes or reads a field to/from the cluster via the client's API. The field here is any data stored in Ignite - the whole key or value of an Ignite entry, an element of an array or set, a field of a complex object, etc.
By using the client's API methods, an application can explicitly specify an Ignite type for a particular field. The client uses this information to transform the field from JavaScript to Java type and vice versa during the read/write operations. The field is transformed into JavaScript type as a result of read operations. It validates the corresponding JavaScript type in inputs of write operations.
If an application does not explicitly specify an Ignite type for a field, the client uses the default mapping during the field read/write operations.
Default Mapping
The default mapping is explained here.
Basic Key-Value Operations
The CacheClient class provides methods for working with the cache entries using key-value operations - put, get, put all, get all, replace and others. The following example shows how to do that:
Scan Queries
The IgniteClient.query(scanquery) method can be used to fetch all entries from the cache. It returns a cursor object that can be used to iterate over a result set lazily or to get all results at once.
To execute a scan query, create a ScanQuery object and call IgniteClient.query(scanquery):
Executing SQL Statements
The Node.js thin client supports all SQL commands that are supported by GridGain. The commands are executed via the query(SqlFieldQuery) method of the cache object. The method accepts an instance of SqlFieldsQuery that represents a SQL statement and returns an instance of the SqlFieldsCursor class. Use the cursor to iterate over the result set or get all results at once.
Security
SSL/TLS
To use encrypted communication between the thin client and the cluster, you have to enable SSL/TLS both in the cluster configuration and the client configuration. Refer to the Enabling SSL/TLS for Thin Clients section for instructions on the cluster configuration.
Here is an example configuration for enabling SSL in the thin client:
Authentication
Configure authentication on the cluster side and provide a valid user name and password in the client configuration.
Authorization
For information about authorizing thin client connections, see the Client Authorization page.
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

