Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
createClient
✓ import { createClient } from 'node-zookeeper-client';
✗ const createClient = require('node-zookeeper-client').createClient;
While CommonJS is the primary usage, modern bundlers may allow named ESM import. The main export is the `zookeeper` object, which has `createClient` as a property.
zookeeper
✓ const zookeeper = require('node-zookeeper-client');
✗ import zookeeper from 'node-zookeeper-client';
This package is primarily CommonJS. Direct `import zookeeper from 'node-zookeeper-client'` (default ESM import) is unlikely to work without specific Node.js configuration or a transpiler, and even then, `zookeeper.createClient` would be the correct access pattern.
Event
✓ const { Event } = require('node-zookeeper-client');
// or
const zookeeper = require('node-zookeeper-client');
const Event = zookeeper.Event;
✗ import { Event } from 'node-zookeeper-client';
Event (and other utility classes like State, Transaction, Exception) are exposed as properties of the main module object.
This example connects to a local ZooKeeper instance, creates an ephemeral node with data, and then attempts to retrieve its data with a watcher, handling potential 'node exists' errors.
const zookeeper = require('node-zookeeper-client');
const client = zookeeper.createClient('localhost:2181');
const path = '/my-test-node'; // Using a fixed path for a runnable example
const data = Buffer.from('Hello ZooKeeper');
client.once('connected', function () {
console.log('Connected to the ZooKeeper server.');
client.create(path, data, zookeeper.ACL.OPEN_ACL_UNSAFE, zookeeper.CreateMode.EPHEMERAL, function (error) {
if (error) {
if (error.getCode() === zookeeper.Exception.NODE_EXISTS) {
console.log('Node %s already exists, skipping creation.', path);
} else {
console.error('Failed to create node: %s due to: %s.', path, error);
client.close();
return;
}
} else {
console.log('Node: %s is successfully created with data: %s.', path, data.toString());
}
// Example of getting data
client.getData(path, function (event) {
console.log('Watcher triggered for %s: %s', path, event);
}, function (error, data, stat) {
if (error) {
console.error('Failed to get data from %s due to: %s.', path, error);
} else {
console.log('Data of %s is: %s (version: %d).', path, data.toString(), stat.version);
}
client.close();
});
});
});
client.on('error', function (error) {
console.error('ZooKeeper client encountered an error: %s', error.stack);
});
client.connect();
Errors
Common errors & fixes
Failed to create node: %s due to: %s. (KeeperErrorCode = NodeExists)
Attempting to create a znode at a path where a node already exists.
fixBefore creating a node, use `client.exists(path, callback)` to check if it already exists. Handle the `NODE_EXISTS` exception explicitly if creating an existing node is an expected scenario.
ZooKeeper client encountered an error: Error: Connection refused
The client could not establish a connection to the specified ZooKeeper server. This often indicates the server is not running, is on a different host/port, or a firewall is blocking the connection.
fixVerify that the ZooKeeper server process is running and accessible from the Node.js application's host and port. Check firewall rules and the `connectionString` passed to `createClient`.
WARN Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect java.net.ConnectException: Connection refused
Similar to 'Connection refused', this warning (often seen in ZK logs or client output) indicates the client lost connection to the server or couldn't initially connect, often due to network issues, incorrect host/port, or the server being down.
fixEnsure the ZooKeeper ensemble is healthy and accessible. Review network configuration and verify the `connectionString`. Also, check ZooKeeper server logs for issues on the server side.
The lib will segfault if you try to use a ZooKeeper instance after the on_closed event is delivered (possibly as a result of session timeout etc.) YOU MAY NOT re-use the closed ZooKeeper instance.
Attempting to perform operations on a `Client` instance after its session has expired or the connection has been explicitly closed, leading to undefined behavior or crashes.
fixUpon receiving a 'disconnected' or 'close' event, dispose of the current `Client` instance. If a new connection is needed, create an entirely new client instance using `zookeeper.createClient()`.
Audit
Dependencies
bufferpackrequiredUsed for packing and unpacking binary data, essential for ZooKeeper wire protocol.
log4jsrequiredUsed for logging within the client, providing various logging levels and appenders.