{"id":16155,"library":"node-zookeeper-client","title":"Node.js Pure JavaScript ZooKeeper Client","description":"node-zookeeper-client is a pure JavaScript client for Apache ZooKeeper, designed to mirror the ZooKeeper Java client API while adhering to Node.js conventions. It provides core functionalities like connecting, creating/removing nodes, retrieving/setting data, and managing ACLs. The current stable version is 1.1.3, last published over four years ago, indicating it is no longer actively maintained. This client has been tested against ZooKeeper version 3.4.*. Unlike some alternatives that wrap the C client, this package is entirely JavaScript-based. Its release cadence is effectively non-existent due to its abandoned status, and it primarily supports callback-based asynchronous operations.","status":"abandoned","version":"1.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/alexguan/node-zookeeper-client","tags":["javascript","zookeeper","client","pure"],"install":[{"cmd":"npm install node-zookeeper-client","lang":"bash","label":"npm"},{"cmd":"yarn add node-zookeeper-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-zookeeper-client","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for packing and unpacking binary data, essential for ZooKeeper wire protocol.","package":"bufferpack","optional":false},{"reason":"Used for logging within the client, providing various logging levels and appenders.","package":"log4js","optional":false}],"imports":[{"note":"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.","wrong":"const createClient = require('node-zookeeper-client').createClient;","symbol":"createClient","correct":"import { createClient } from 'node-zookeeper-client';"},{"note":"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.","wrong":"import zookeeper from 'node-zookeeper-client';","symbol":"zookeeper","correct":"const zookeeper = require('node-zookeeper-client');"},{"note":"Event (and other utility classes like State, Transaction, Exception) are exposed as properties of the main module object.","wrong":"import { Event } from 'node-zookeeper-client';","symbol":"Event","correct":"const { Event } = require('node-zookeeper-client');\n// or\nconst zookeeper = require('node-zookeeper-client');\nconst Event = zookeeper.Event;"}],"quickstart":{"code":"const zookeeper = require('node-zookeeper-client');\n\nconst client = zookeeper.createClient('localhost:2181');\nconst path = '/my-test-node'; // Using a fixed path for a runnable example\nconst data = Buffer.from('Hello ZooKeeper');\n\nclient.once('connected', function () {\n    console.log('Connected to the ZooKeeper server.');\n\n    client.create(path, data, zookeeper.ACL.OPEN_ACL_UNSAFE, zookeeper.CreateMode.EPHEMERAL, function (error) {\n        if (error) {\n            if (error.getCode() === zookeeper.Exception.NODE_EXISTS) {\n                console.log('Node %s already exists, skipping creation.', path);\n            } else {\n                console.error('Failed to create node: %s due to: %s.', path, error);\n                client.close();\n                return;\n            }\n        } else {\n            console.log('Node: %s is successfully created with data: %s.', path, data.toString());\n        }\n\n        // Example of getting data\n        client.getData(path, function (event) {\n            console.log('Watcher triggered for %s: %s', path, event);\n        }, function (error, data, stat) {\n            if (error) {\n                console.error('Failed to get data from %s due to: %s.', path, error);\n            } else {\n                console.log('Data of %s is: %s (version: %d).', path, data.toString(), stat.version);\n            }\n            client.close();\n        });\n    });\n});\n\nclient.on('error', function (error) {\n    console.error('ZooKeeper client encountered an error: %s', error.stack);\n});\n\nclient.connect();","lang":"javascript","description":"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."},"warnings":[{"fix":"Migrate to `zookeeper` package for active maintenance and support for newer ZooKeeper server versions.","message":"This package (node-zookeeper-client by alexguan) is effectively abandoned, with the last publish over four years ago. It only supports ZooKeeper server versions up to 3.4.*, which is severely outdated. For modern ZooKeeper versions (3.5.x+) and active development, consider the `zookeeper` package (yfinkelstein/node-zookeeper) which uses the C client bindings.","severity":"breaking","affected_versions":"1.1.3"},{"fix":"Upgrade to the latest available version (1.1.3) within this package if forced to use it, but strongly consider migrating to the actively maintained `zookeeper` package for better security posture.","message":"Older versions of this package (1.0.0, 1.1.0, 1.1.1) have known 'severe vulnerabilities exploited'. While the latest 1.1.3 might implicitly fix some, the lack of active maintenance means new vulnerabilities are unlikely to be addressed. It's not recommended for production use due to security risks.","severity":"breaking","affected_versions":">=1.0.0 <1.1.3"},{"fix":"Wrap callback-based functions with `util.promisify` or custom Promise wrappers if modern async/await syntax is desired, or migrate to a more modern client like `zookeeper`.","message":"This client primarily uses callback-based asynchronous patterns, typical for older Node.js modules. It does not natively support Promises or async/await syntax, which can lead to callback hell in complex applications.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure event listeners are set up for 'connected', 'disconnected', and 'error' on the client instance to correctly manage connection state and handle failures. For example: `client.once('connected', ...)` and `client.on('error', ...)`.","message":"The client handles ZooKeeper connection state changes and watcher events through an event emitter API. Developers must explicitly listen for the 'connected', 'disconnected', and 'error' events to manage the client lifecycle and react to network issues or session expirations.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Before 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.","cause":"Attempting to create a znode at a path where a node already exists.","error":"Failed to create node: %s due to: %s. (KeeperErrorCode = NodeExists)"},{"fix":"Verify 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`.","cause":"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.","error":"ZooKeeper client encountered an error: Error: Connection refused"},{"fix":"Ensure 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.","cause":"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.","error":"WARN Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect java.net.ConnectException: Connection refused"},{"fix":"Upon 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()`.","cause":"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.","error":"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."}],"ecosystem":"npm"}