-
Notifications
You must be signed in to change notification settings - Fork 107
DOC-548: Migrate tech content from node.js readme & ref manual to Docs #1791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
24bf431
DOC-548: add readme content WIP
amandalindsay 59e6569
DOC-548: add info from readme & ref manual
amandalindsay cce6a0b
DOC-548: tweaks
amandalindsay 10e93d5
DOC-548: tweaked links, removed comments
amandalindsay 479d87c
DOC-548: updates to feature list
amandalindsay b92bdd7
Merge branch 'main' into DOC-548
amandalindsay 016fae2
Merge branch 'main' into DOC-548
amandalindsay 0bdef28
Update docs/modules/clients/pages/nodejs.adoc
amandalindsay 37415b5
Update docs/modules/clients/pages/nodejs.adoc
amandalindsay a2ee95c
Update docs/modules/clients/pages/nodejs.adoc
amandalindsay bb8f225
DOC-548: updates from feedback
amandalindsay 7f54fcf
Merge branch 'DOC-548' of https://github.com/hazelcast/hz-docs into D…
amandalindsay 8b7e3e8
Merge branch 'main' into DOC-548
amandalindsay d24e2c5
Update docs/modules/clients/pages/nodejs.adoc
amandalindsay 0c9fa92
Update docs/modules/clients/pages/nodejs.adoc
amandalindsay e79a8a0
Update docs/modules/clients/pages/nodejs.adoc
amandalindsay 05b4fb9
Update docs/modules/clients/pages/nodejs.adoc
amandalindsay 14f7793
Update docs/modules/clients/pages/nodejs.adoc
amandalindsay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,149 @@ | ||
= Node.js Client | ||
:page-api-reference: http://hazelcast.github.io/hazelcast-nodejs-client/api/{page-latest-supported-nodejs-client}/docs/ | ||
|
||
TIP: For the latest Node.js API documentation, see http://hazelcast.github.io/hazelcast-nodejs-client/api/{page-latest-supported-nodejs-client}/docs/[Hazelcast Node.js Client docs]. | ||
== Overview | ||
|
||
This section provides information about the Node.js client for Hazelcast, and explains how to install and get started with the client. | ||
|
||
TIP: To learn how to get started quickly with the Hazelcast Node.js client, follow our xref:clients:nodejs-client-getting-started.adoc[Get started with Node.js] tutorial. | ||
|
||
The Hazelcast native Node.js client is an official library that allows Node.js applications to connect to and interact with Hazelcast clusters. It is implemented using the Hazelcast Open Binary Client Protocol, and provides a promise-based API with built-in support for native JavaScript objects. The key features and benefits include: | ||
The official Hazelcast Node.js client is a library that allows Node.js applications to connect to and interact with a Hazelcast cluster, enabling features such as distributed maps, caching, and more. It provides a promise-based API with built-in support for native JavaScript objects. The key features and benefits include: | ||
|
||
* Distributed data structures: the client offers access to various distributed data structures like Map, MultiMap, Set, List, Queue, and more | ||
* Multi-layer caching: you can build a multi-layer cache for your applications using Hazelcast Map, which is a distributed and replicated key-value store | ||
* Fast JSON querying: the client allows querying JSON data at speeds surpassing traditional document stores | ||
* Near Cache: this allows storing frequently read data in your Node.js process, providing faster read speeds than popular caching solutions | ||
* Pub-sub communication: the client enables pub-sub communication between application instances | ||
* Prevent races with Lock: the client provides locking mechanisms to prevent race conditions when accessing shared resources | ||
* SQL support: the client supports SQL queries for optimized distributed queries on the keys and values of maps in a local cluster | ||
|
||
* Distributed, partitioned and queryable in-memory key-value store implementation, called **Map** | ||
* Eventually consistent cache implementation to store a subset of the Map data locally in the memory of the client, called **Near Cache** | ||
* Additional data structures and simple messaging constructs such as **Set**, **MultiMap**, **Queue**, **Topic** | ||
* Cluster-wide unique ID generator, called **FlakeIdGenerator** | ||
* Distributed, CRDT-based counter, called **PNCounter** | ||
* Distributed concurrency primitives from CP Subsystem, such as **FencedLock**, **Semaphore**, **AtomicLong** | ||
* Integration with https://cloud.hazelcast.com/[Hazelcast Cloud] | ||
* Support for serverless and traditional web service architectures with **Unisocket** and **Smart** operation modes | ||
* Ability to listen to client lifecycle, cluster state and distributed data structure events | ||
|
||
These features make the Hazelcast Node.js client a powerful tool for building distributed, high-performance Node.js applications to leverage Hazelcast's in-memory computing capabilities. | ||
|
||
TIP: For the latest Node.js API documentation, see http://hazelcast.github.io/hazelcast-nodejs-client/api/{page-latest-supported-nodejs-client}/docs/[Hazelcast Node.js Client docs]. | ||
|
||
== Install the Node.js client | ||
|
||
This section explains how to set up a Hazelcast cluster and install the Hazelcast Node.js client. | ||
|
||
=== Set up a Hazelcast cluster | ||
|
||
The Hazelcast Node.js client requires a working Hazelcast cluster to run. The cluster handles storage and manipulation of the user data. Clients are a way to connect to the Hazelcast cluster and access the data. | ||
|
||
The quickest way to start a single member cluster for development purposes is to use our https://hub.docker.com/r/hazelcast/hazelcast/[Docker images]. | ||
|
||
Launch a Hazelcast Docker Container by running the following command: | ||
|
||
```bash | ||
docker run -p 5701:5701 hazelcast/hazelcast | ||
``` | ||
This command fetches the latest Hazelcast version. You can find all available tags | ||
https://hub.docker.com/r/hazelcast/hazelcast/tags[here]. | ||
|
||
TIP: For a step-by-step guide, see the https://docs.hazelcast.com/hazelcast/latest/getting-started/get-started-docker[Start a local cluster in Docker] and https://docs.hazelcast.com/hazelcast/latest/getting-started/enterprise-overview[Get Started with Hazelcast Enterprise Edition] tutorials. | ||
|
||
Alternatively, you can run standalone members by downloading and running distribution files from the Hazelcast website as follows: | ||
|
||
. Go to the download page and choose either the https://hazelcast.com/open-source-projects/downloads/[ZIP or TAR distribution] of Hazelcast. | ||
. Decompress the contents into the directory that you want to run members from. | ||
. Change into this directory and then start the Hazelcast member using the ``./bin/hz start`` command. | ||
|
||
The Hazelcast log appears in the terminal showing that your 1-member cluster is ready to be used. | ||
|
||
=== Install the client library | ||
|
||
Use the `npm install` command to install the Hazelcast Node.js client library into your project. | ||
|
||
```bash | ||
npm install hazelcast-client --save | ||
``` | ||
After running this command, you can use the Hazelcast client in your Node.js code to access Hazelcast data structures and services. | ||
|
||
== Use the client | ||
|
||
This section shows how to connect to a Hazelcast cluster and perform some basic operations using the client. | ||
|
||
*Example: Connect to a Hazelcast cluster* | ||
|
||
Import the Client class from the Hazelcast Node.js client library. This creates a new Hazelcast client instance and connects to a Hazelcast cluster using the default configuration. The `await` keyword ensures that the code waits for the client to successfully connect before proceeding. | ||
|
||
```js | ||
const { Client } = require('hazelcast-client'); | ||
const client = await Client.newHazelcastClient(); | ||
``` | ||
|
||
*Example: Get or create the 'distributed-map' on the cluster* | ||
|
||
```js | ||
const map = await client.getMap('distributed-map'); | ||
``` | ||
|
||
*Example: Put 'key', 'value' pair into the 'distributed-map'* | ||
|
||
```js | ||
await map.put('key', 'value'); | ||
``` | ||
|
||
*Example: Get the value associated with the given key from the cluster* | ||
|
||
```js | ||
const value = await map.get('key'); | ||
console.log(value); // Outputs 'value' | ||
``` | ||
|
||
*Example: Shut down the client* | ||
|
||
```js | ||
await client.shutdown(); | ||
``` | ||
|
||
NOTE: To see the complete code, see this https://github.com/hazelcast/hazelcast-nodejs-client/tree/master/code_samples/readme_sample.js[code sample]. | ||
|
||
== Configure the client | ||
|
||
If you are running Hazelcast and the Node.js client on the same machine, the default configuration should work 'out of the box'. | ||
However, if you run the client on a different computer to that of the cluster members, you may need to do some simple configuration, such as specifying member addresses, or customizing client properties. | ||
|
||
The following shows how to configure and connect a Hazelcast Node.js client to a specific Hazelcast cluster, listen for lifecycle events, and then shut down the client: | ||
|
||
```js | ||
const { Client } = require('hazelcast-client'); | ||
|
||
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(); | ||
``` | ||
|
||
To learn more about supported configuration options, see the | ||
https://github.com/hazelcast/hazelcast-nodejs-client/blob/master/DOCUMENTATION.md[Node.js client documentation] | ||
|
||
|
||
== Get support | ||
|
||
Join us in the https://hazelcastcommunity.slack.com/channels/nodejs-client[Node.js client channel]. | ||
Get an invite via https://slack.hazelcast.com/[Slack]. | ||
|
||
Raise an issue in the https://github.com/hazelcast/hazelcast-nodejs-client/issues[GitHub repository]. | ||
|
||
== Next steps | ||
|
||
For more information, see the Hazelcast Node.js client GitHub https://github.com/hazelcast/hazelcast-nodejs-client[repo^] | ||
and https://github.com/hazelcast/hazelcast-nodejs-client/tree/master/code_samples[code samples^]. | ||
For more information, see: | ||
|
||
- Hazelcast Node.js client GitHub https://github.com/hazelcast/hazelcast-nodejs-client[repo^] | ||
- https://github.com/hazelcast/hazelcast-nodejs-client/tree/master/code_samples[Code samples^] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not very important, but an extra blank line was introduced here.