Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
node-zookeeper - A Node.js client for Apache Zookeeper.
This node module is implemented on top of the official ZooKeeper C Client API, supporting ZooKeeper server v3.5.x - v3.8.x. Have a look at the official docs for further details on behavior.
Latest changes are described in the changelog
npm install zookeeper
And you're done!
(note the name zookeeper
in lowercase)
:rocket: New since version 5.4.0 It is possible to start the zookeeper client in a Node.js Worker thread.
:rocket: New since version 5.1.0 Support for SSL
, that was introduced in Apache ZooKeeper C Client v3.6.0.
:rocket: New since version 4.9.0 Support for Dynamic Reconfiguration
, introduced in Apache ZooKeeper server v3.5.5.
:rocket: New since version 4.8.0 Support for the new node types introduced in Apache ZooKeeper server v3.5.5: Container
and TTL
:rocket:
:tada: New since version 4.7.0 :tada: The install process is faster than ever. If you are a Mac OS X or Windows user, there is no longer a need to build an AddOn during the install process.
Everything is already included in the package. Linux user? Don't worry, the installer will quickly build a Native Node.js AddOn
for the Linux flavor you are running.
const ZooKeeper = require('zookeeper');
The ZooKeeper client support both callbacks and Promises using the then
or async/await
syntax.
The source code is documented with JSDoc
code comments and TypeScript
type declarations.
Also, have a look at the API documentation here:
Create an instance of the ZooKeeper client:
function createClient(timeoutMs = 5000) {
const config = {
connect: host,
timeout: timeoutMs,
debug_level: ZooKeeper.ZOO_LOG_LEVEL_WARN,
host_order_deterministic: false,
};
return new ZooKeeper(config);
}
const client = createClient();
The client is ready when connected to a ZooKeeper server:
client.on('connect', () => {
// start using the client
});
client.init(config);
Using the API:
const path = '/myPath';
try {
const createdPath = await client.create(path, data, ZooKeeper.ZOO_EPHEMERAL);
console.log(`(created: ${createdPath})`);
} catch (error) {
console.log(`${path} already exists`);
}
Have a look at the code in the examples folder: with master, workers, tasks and listeners scenarios.
:green_circle: New since 5.2.1: :red_circle: the async functions will reject, when the underlying client returns an error code. This is a bug fix. Before this, errors were failing silently.
init(options)
connect(options, connect_cb)
close()
path = await create(path, data, flags, ttl)
ttl
is optional. Must be positive if a TTL flag is used. See Input parametersmkdirp(path, callback(Error))
stat = await exists(path, watch)
pathExists
as an alternative.trueOrFalseValue = await pathExists(path, watch)
[stat, string|Buffer] = await get(path, watch)
children = await get_children(path, watch)
[children, stat] = await get_children2( path, watch)
stat = await set(path, data, version)
val = await sync(path)
delete_ (path, version)
_
)config = getconfig(watch)
reconfig(joining, leaving, members, config_version)
set_acl(path, version, acl)
acl = await get_acl(path)
add_auth(scheme, auth)
The watcher methods are forward-looking subscriptions that can recieve multiple callbacks whenever a matching event occurs.
stat = await w_exists(path, watch_cb)
w_pathExists
as an alternative.trueOrFalseValue = await w_pathExists(path, watch)
[stat, string|Buffer] = await w_get(path, watch_cb)
children = await w_get_children(path, watch_cb)
[children, stat] = await w_get_children2 (path, watch_cb)
config = w_getconfig(watch_cb)
init(options)
connect(options, connect_cb)
close()
a_create(path, data, flags, path_cb)
a_createTtl(path, data, flags, ttl, pathCb)
mkdirp(path, callback(Error))
a_exists(path, watch, stat_cb)
a_get(path, watch, data_cb)
a_get_children(path, watch, child_cb)
a_get_children2(path, watch, child2_cb)
a_set(path, data, version, stat_cb)
a_sync(path, value_cb)
a_delete_ (path, version, void_cb)
_
)a_getconfig(watch, data_cb)
a_reconfig(joining, leaving, members, version, data_cb)
a_set_acl(path, version, acl, void_cb)
a_get_acl(path, acl_cb)
add_auth(scheme, auth, void_cb)
The watcher methods are forward-looking subscriptions that can recieve multiple callbacks whenever a matching event occurs.
aw_exists(path, watch_cb, stat_cb)
aw_get(path, watch_cb, data_cb)
aw_get_children(path, watch_cb, child_cb)
aw_get_children2(path, watch_cb, child2_cb)
aw_getconfig(watch_cb, data_cb)
ZOO_PERSISTENT
ZOO_EPHEMERAL
ZOO_PERSISTENT_SEQUENTIAL
ZOO_EPHEMERAL_SEQUENTIAL
ZOO_CONTAINER
ZOO_PERSISTENT_WITH_TTL
ZOO_PERSISTENT_SEQUENTIAL_WITH_TTL
null
or undefined
will skip version checking.undefined
.null
for non-incremental reconfiguration.null
for non-incremental reconfiguration.null
for incremental reconfiguration.-1
to skip version checkingSession state machine is well described in the Zookeeper docs
The library comes with 3 default ACL levels defined (comes from ZK):
If you don't want to use predefined ACLs you can define your own (the ACL object is described above), for limiting permisions you can use:
For more details please refer to ZooKeeper docs.
Windows 10 is supported out of the box with no additional requirements other than Node.js itself.
Running a different Windows version? Install CMake
to build a ZooKeeper client on Windows and install Python.
Also, run npm install
in a Powershell window. For further instructions visit node-gyp documentation.
Windows support has been enabled mainly for supporting development, not for production.
To run full output during the module build one has to use ZK_INSTALL_VERBOSE
flag.
ZK_INSTALL_VERBOSE=1 npm install
$env:ZK_INSTALL_VERBOSE=1
npm install
This PowerShell command will remove the environment variable:
Remove-Item Env:\ZK_INSTALL_VERBOSE
Check out the issues tab and grab one! Read the contributing document.
See LICENSE-MIT.txt file in the top level folder.
Yuri Finkelstein (yurif2003 at yahoo dot com)
with awesome contributions from:
FAQs
apache zookeeper client (zookeeper async API v3.5.x - v3.8.x)
The npm package zookeeper receives a total of 4,578 weekly downloads. As such, zookeeper popularity was classified as popular.
We found that zookeeper demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.