Hazelcast is an open-source distributed in-memory data store and computation platform that provides a wide variety of distributed data structures and concurrency primitives.
Hazelcast Node.js client is a way to communicate to Hazelcast clusters and access the cluster data. The client provides a Promise-based API with a builtin support for native JavaScript objects.
Hazelcast Node.js client requires a working Hazelcast cluster to run. This cluster handles the storage and manipulation of the user data.
A Hazelcast cluster consists of one or more cluster members. These members generally run on multiple virtual or physical machines and are connected to each other via the network. Any data put on the cluster is partitioned to multiple members transparent to the user. It is therefore very easy to scale the system by adding new members as the data grows. Hazelcast cluster also offers resilience. Should any hardware or software problem causes a crash to any member, the data on that member is recovered from backups and the cluster continues to operate without any downtime.
The quickest way to start a single member cluster for development purposes is to use our Docker images.
docker run -p 5701:5701 hazelcast/hazelcast
This command fetches the latest Hazelcast version. You can find all available tags here.
You can also use our ZIP or TAR distributions as described here.
npm install hazelcast-client
const { Client } = require('hazelcast-client');
// Connect to Hazelcast cluster
const client = await Client.newHazelcastClient();
// Get or create the 'distributed-map' on the cluster
const map = await client.getMap('distributed-map');
// Put 'key', 'value' pair into the 'distributed-map'
await map.put('key', 'value');
// Get the value associated with the given key from the cluster
const value = await map.get('key');
console.log(value); // Outputs 'value'
// Shutdown the client
await client.shutdown();
NOTE: For the sake of brevity we are going to omit boilerplate parts in the above code snippet. Refer to this code sample to see the complete code.
If you are using Hazelcast and the Node.js client on the same machine, the default configuration should work out-of-the-box. However, you may need to configure the client to connect to cluster nodes that are running on different machines or to customize client properties.
const { Client } = require('hazelcast-client');
// Initialize the client with the given configuration
const client = await Client.newHazelcastClient({
clusterName: 'cluster-name',
network: {
clusterMembers: [
'10.90.0.2:5701',
'10.90.0.3:5701'
]
},
lifecycleListeners: [
(state) => {
console.log('Lifecycle Event >>> ' + state);
}
]
});
console.log('Connected to cluster');
await client.shutdown();
Refer to the documentation to learn more about supported configuration options.
You can use the following channels for your questions and development/usage issues:
We encourage any type of contribution in the form of issue reports or pull requests.
For issue reports, please share the following information with us to quickly resolve the problems.
Contributions are submitted, reviewed and accepted using the pull requests on GitHub. For an enhancement or larger feature, create a GitHub issue first to discuss.
npm install
to automatically download and install all the required modules.npm run compile
to compile TypeScript files to JavaScript.npm run lint
and fix the reported issues, if any.In order to test Hazelcast Node.js client locally, you will need the following:
Following command starts the tests:
npm test
Test script automatically downloads hazelcast-remote-controller
and Hazelcast. The script uses Maven to download those.
In order to run specific tests, you can give a pattern to the test command like the following:
npm test pattern
This command will only run the tests matching the pattern. The pattern can be a string or regex in the same form
grep
command accepts.
Copyright (c) 2008-2022, Hazelcast, Inc. All Rights Reserved.
Visit www.hazelcast.com for more information.
Generated using TypeDoc