{"id":13474820,"url":"https://github.com/alexguan/node-zookeeper-client","last_synced_at":"2025-03-26T22:31:19.807Z","repository":{"id":8240736,"uuid":"9684364","full_name":"alexguan/node-zookeeper-client","owner":"alexguan","description":"A pure Javascript ZooKeeper client for Node.js","archived":false,"fork":false,"pushed_at":"2024-02-16T05:35:57.000Z","size":311,"stargazers_count":540,"open_issues_count":63,"forks_count":147,"subscribers_count":26,"default_branch":"master","last_synced_at":"2024-10-30T08:50:41.529Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexguan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-04-26T00:28:13.000Z","updated_at":"2024-10-25T10:17:41.000Z","dependencies_parsed_at":"2024-06-05T10:20:46.859Z","dependency_job_id":null,"html_url":"https://github.com/alexguan/node-zookeeper-client","commit_stats":{"total_commits":129,"total_committers":13,"mean_commits":9.923076923076923,"dds":"0.12403100775193798","last_synced_commit":"eec7a566a2e9ce7f148f3092d677054bb5b1d345"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexguan%2Fnode-zookeeper-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexguan%2Fnode-zookeeper-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexguan%2Fnode-zookeeper-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexguan%2Fnode-zookeeper-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexguan","download_url":"https://codeload.github.com/alexguan/node-zookeeper-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245747699,"owners_count":20665843,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T16:01:15.073Z","updated_at":"2025-03-26T22:31:18.741Z","avatar_url":"https://github.com/alexguan.png","language":"JavaScript","readme":"# node-zookeeper-client\n\nA pure Javascript [ZooKeeper](http://zookeeper.apache.org) client module for\n[Node.js](http://nodejs.org).\n\n[![NPM](https://nodei.co/npm/node-zookeeper-client.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/node-zookeeper-client/)\n\n[![Build Status](https://travis-ci.org/alexguan/node-zookeeper-client.png?branch=master)](https://travis-ci.org/alexguan/node-zookeeper-client)\n\nThis module is designed to resemble the ZooKeeper Java client API but with\ntweaks to follow the convention of Node.js modules. Developers that are familiar\nwith the ZooKeeper Java client would be able to pick it up quickly.\n\nThis module has been tested to work with ZooKeeper version 3.4.*.\n\n---\n\n+ [Installation](#installation)\n+ [Example](#example)\n+ [Documentation](#documentation)\n    + [createClient](#client-createclientconnectionstring-options)\n    + [Client](#client)\n        + [connect](#void-connect)\n        + [close](#void-close)\n        + [create](#void-createpath-data-acls-mode-callback)\n        + [remove](#void-removepath-version-callback)\n        + [removeRecursive](#void-removerecursivepath-version-callback)\n        + [exists](#void-existspath-watcher-callback)\n        + [getChildren](#void-getchildrenpath-watcher-callback)\n        + [listSubTreeBFS](#void-listsubtreebfspath-callback)\n        + [getData](#void-getdatapath-watcher-callback)\n        + [setData](#void-setdatapath-data-version-callback)\n        + [getACL](#void-getaclpath-callback)\n        + [setACL](#void-setaclpath-acls-version-callback)\n        + [transaction](#transaction-transaction)\n        + [mkdirp](#void-mkdirppath-data-acls-mode-callback)\n        + [addAuthInfo](#void-addauthinfoscheme-auth)\n        + [getState](#state-getstate)\n        + [getSessionId](#buffer-getsessionid)\n        + [getSessionPassword](#buffer-getsessionpassword)\n        + [getSessionTimeout](#number-getsessiontimeout)\n    + [State](#state)\n    + [Event](#event)\n    + [Transaction](#transaction)\n        + [create](#transaction-createpath-data-acls-mode)\n        + [setData](#transaction-setdatapath-data-version)\n        + [check](#transaction-checkpath-version)\n        + [remove](#transaction-removepath-data-version)\n        + [commit](#void-commitcallback)\n    + [Exception](#exception)\n        + [getCode](#number-getcode)\n        + [getPath](#string-getpath)\n        + [getName](#string-getname)\n        + [toString](#string-tostring)\n    + [Exception](#exception)\n+ [Dependency](#dependency)\n+ [License](#license)\n\n## Installation\n\nYou can install it using npm:\n\n```bash\n$ npm install node-zookeeper-client\n```\n\n## Example\n\n1\\. Create a node using given path:\n\n```javascript\nvar zookeeper = require('node-zookeeper-client');\n\nvar client = zookeeper.createClient('localhost:2181');\nvar path = process.argv[2];\n\nclient.once('connected', function () {\n    console.log('Connected to the server.');\n\n    client.create(path, function (error) {\n        if (error) {\n            console.log('Failed to create node: %s due to: %s.', path, error);\n        } else {\n            console.log('Node: %s is successfully created.', path);\n        }\n\n        client.close();\n    });\n});\n\nclient.connect();\n```\n\n2\\. List and watch the children of given node:\n\n```javascript\nvar zookeeper = require('node-zookeeper-client');\n\nvar client = zookeeper.createClient('localhost:2181');\nvar path = process.argv[2];\n\nfunction listChildren(client, path) {\n    client.getChildren(\n        path,\n        function (event) {\n            console.log('Got watcher event: %s', event);\n            listChildren(client, path);\n        },\n        function (error, children, stat) {\n            if (error) {\n                console.log(\n                    'Failed to list children of %s due to: %s.',\n                    path,\n                    error\n                );\n                return;\n            }\n\n            console.log('Children of %s are: %j.', path, children);\n        }\n    );\n}\n\nclient.once('connected', function () {\n    console.log('Connected to ZooKeeper.');\n    listChildren(client, path);\n});\n\nclient.connect();\n```\n\nMore examples can be found [here](examples).\n\n\n## Documentation\n\n#### Client createClient(connectionString, [options])\n\nFactory method to create a new zookeeper [client](#client) instance.\n\n**Arguments**\n\n* connectionString `String` - Comma separated `host:port` pairs, each\n  represents a ZooKeeper server. You can optionally append a chroot path, then\n  the client would be rooted at the given path. e.g.\n\n  ```javascript\n  'localhost:3000,locahost:3001,localhost:3002'\n  'localhost:2181,localhost:2182/test'\n  ```\n\n* options `Object` - An object to set the client options. Currently available\n  options are:\n\n    * `sessionTimeout` Session timeout in milliseconds, defaults to 30 seconds.\n    * `spinDelay` The delay (in milliseconds) between each connection attempts.\n    * `retries` The number of retry attempts for connection loss exception.\n\n  Defaults options:\n\n    ```javascript\n    {\n        sessionTimeout: 30000,\n        spinDelay : 1000,\n        retries : 0\n    }\n    ```\n\n**Example**\n\n```javascript\nvar client = zookeeper.createClient(\n    'localhost:2181/test',\n    { sessionTimeout: 10000 }\n);\n```\n\n---\n\n### Client\n\nThis is the main class of ZooKeeper client module. An application must\nuse [`createClient`](#createclientconnectionstring-options) method to\ninstantiate the client.\n\nOnce a connection from the client to the server is established, a session id is\nassigned to the client. The client will starts sending heart beats to the server\nperiodically to keep the session valid.\n\nIf the client fails to send heart beats to the server for a prolonged period of\ntime (exceeding the sessionTimeout value), the server will expire the session.\nThe client object will no longer be usable.\n\nIf the ZooKeeper server the client currently connects to fails or otherwise\ndoes not respond, the client will automatically try to connect to another server\nbefore its session times out. If successful, the application can continue to\nuse the client.\n\nThis class inherits from [events.EventEmitter](http://nodejs.org/api/events.html)\nclass, see [Event](#event) for details.\n\n#### void connect()\n\nInitiate the connection to the provided server list (ensemble). The client will\npick an arbitrary server from the list and attempt to connect to it. If the\nestablishment of the connection fails, another server will be tried (picked\nrandomly) until a connection is established or [close](#close) method is\ninvoked.\n\n---\n\n#### void close()\n\nClose this client. Once the client is closed, its session becomes invalid.\nAll the ephemeral nodes in the ZooKeeper server associated with the session\nwill be removed. The watchers left on those nodes (and on their parents) will\nbe triggered.\n\n---\n\n#### void create(path, [data], [acls], [mode], callback)\n\nCreate a node with given path, data, acls and mode.\n\n**Arguments**\n\n* path `String` - Path of the node.\n* data `Buffer` - The data buffer, optional, defaults to null.\n* acls `Array` - An array of [ACL](#acl) objects, optional, defaults to\n  `ACL.OPEN_ACL_UNSAFE`\n* mode `CreateMode` -  The creation mode, optional, defaults to\n  `CreateMode.PERSISTENT`\n* callback(error, path) `Function` - The callback function.\n\n**Example**\n\n```javascript\nzookeeper.create(\n    '/test/demo',\n    Buffer.from('data'),\n    CreateMode.EPHEMERAL,\n    function (error, path) {\n        if (error) {\n            console.log(error.stack);\n            return;\n        }\n\n        console.log('Node: %s is created.', path);\n    }\n);\n```\n\n---\n\n#### void remove(path, [version], callback)\n\nDelete a node with the given path and version. If version is provided and not\nequal to -1, the request will fail when the provided version does not match the\nserver version.\n\n**Arguments**\n\n* path `String` - Path of the node.\n* version `Number` - The version of the node, optional, defaults to -1.\n* callback(error) `Function` - The callback function.\n\n**Example**\n\n```javascript\nzookeeper.remove('/test/demo', -1, function (error) {\n    if (error) {\n        console.log(error.stack);\n        return;\n    }\n\n    console.log('Node is deleted.');\n});\n```\n\n---\n\n#### void removeRecursive(path, [version], callback)\n\nDeletes a node and all its children with the given path and version.\n\n**Arguments**\n\n* path `String` - Path of the node.\n* version `Number` - The version of the node, optional, defaults to -1.\n* callback(error) `Function` - The callback function.\n\n**Example**\n\n```javascript\nzookeeper.removeRecursive('/test/demo', -1, function (error) {\n    if (error) {\n        console.log(error.stack);\n        return;\n    }\n\n    console.log('Nodes removed.');\n});\n```\n\n---\n\n#### void exists(path, [watcher], callback)\n\nCheck the existence of a node. The callback will be invoked with the\nstat of the given path, or `null` if no such node exists.\n\nIf the watcher function is provided and the operation is successful (no error),\na watcher will be placed on the node with the given path. The watcher will be\ntriggered by a successful operation that creates the node, deletes the node or\nsets the data on the node.\n\n**Arguments**\n\n* path `String` - Path of the node.\n* watcher(event) `Function` - The watcher function, optional. The `event` is an\n  instance of [`Event`](#event)\n* callback(error, stat) `Function` - The callback function. The `stat` is an\n  instance of [`Stat`](#stat).\n\n**Example**\n\n```javascript\nzookeeper.exists('/test/demo', function (error, stat) {\n    if (error) {\n        console.log(error.stack);\n        return;\n    }\n\n    if (stat) {\n        console.log('Node exists.');\n    } else {\n        console.log('Node does not exist.');\n    }\n});\n```\n\n---\n\n#### void getChildren(path, [watcher], callback)\n\nFor the given node path, retrieve the children list and the stat. The children\nwill be an unordered list of strings.\n\nIf the watcher callback is provided and the operation is successfully, a watcher\nwill be placed the given node. The watcher will be triggered\nwhen an operation successfully deletes the given node or creates/deletes\nthe child under it.\n\n**Arguments**\n\n* path `String` - Path of the node.\n* watcher(event) `Function` - The watcher function, optional. The `event` is an\n  instance of [`Event`](#event)\n* callback(error, children, stat) `Function` - The callback function. The\n  children is an array of strings and the `stat` is an instance of\n  [`Stat`](#stat).\n\n**Example**\n\n```javascript\nzookeeper.getChildren('/test/demo', function (error, children, stats) {\n    if (error) {\n        console.log(error.stack);\n        return;\n    }\n\n    console.log('Children are: %j.', children);\n});\n```\n\n---\n\n#### void listSubTreeBFS(path, callback)\n\nRetrieve a list of all children including itself for the given node path.\n\n**Arguments**\n\n* path `String` - Path of the node.\n* callback(error, children) `Function` - The callback function. The\n  children is an array of strings.\n\n**Example**\n\n```javascript\nzookeeper.listSubTreeBFS('/test/demo', function (error, children) {\n    if (error) {\n        console.log(error.stack);\n        return;\n    }\n\n    console.log('Children are: %j.', children);\n});\n```\n\n---\n\n#### void getData(path, [watcher], callback)\n\nRetrieve the data and the stat of the node of the given path. If the watcher\nfunction is provided and the operation is successful (no error), a watcher\nwill be placed on the node with the given path. The watch will be triggered by\na successful operation which sets data on the node, or deletes the node.\n\n**Arguments**\n\n* path `String` - Path of the node.\n* watcher(event) `Function` - The watcher function, optional. The `event` is an\n  instance of [`Event`](#event)\n* callback(error, data, stat) `Function` - The callback function. The `data` is\n  an instance of [`Buffer`](http://nodejs.org/api/buffer.html) and stat is an\n  instance of [`Stat`](#stat).\n\n**Example**\n\n```javascript\nzookeeper.getData(\n    '/test/demo',\n    function (event) {\n        console.log('Got event: %s.', event);\n    },\n    function (error, data, stat) {\n        if (error) {\n            console.log(error.stack);\n            return;\n        }\n\n        console.log('Got data: %s', data.toString('utf8'));\n    }\n);\n```\n\n---\n\n#### void setData(path, data, [version], callback)\n\nSet the data for the node of the given path if such a node exists and the\noptional given version matches the version of the node (if the given\nversion is -1, it matches any node's versions). The [stat](#stat) of the node\nwill be returned through the callback function.\n\n**Arguments**\n\n* path `String` - Path of the node.\n* data `Buffer` - The data buffer.\n* version `Number` - The version of the node, optional, defaults to -1.\n* callback(error, stat) `Function` - The callback function. The `stat` is an\n  instance of [`Stat`](#stat).\n\n**Example**\n\n```javascript\nzookeeper.setData('/test/demo', null, 2, function (error, stat) {\n    if (error) {\n        console.log(error.stack);\n        return;\n    }\n\n    console.log('Data is set.');\n});\n```\n\n---\n\n#### void getACL(path, callback)\n\nRetrieve the list of [ACL](#acl) and stat of the node of the given path.\n\n**Arguments**\n\n* path `String` - Path of the node.\n* callback(error, acls, stat) `Function` - The callback function. `acls` is an\n  array of [`ACL`](#acl) instances. The `stat` is an instance of\n  [`Stat`](#stat).\n\n**Example**\n\n```javascript\nzookeeper.getACL('/test/demo', function (error, acls, stat) {\n    if (error) {\n        console.log(error.stack);\n        return;\n    }\n\n    console.log('ACL(s) are: %j', acls);\n});\n```\n\n---\n\n#### void setACL(path, acls, [version], callback)\n\nSet the [ACL](#acl) for the node of the given path if such a node exists and the\ngiven version (optional) matches the version of the node on the server. (if the\ngiven version is -1, it matches any versions).\n\n**Arguments**\n\n* path `String` - Path of the node.\n* acls `Array` - An array of [`ACL`](#acl) instances.\n* version `Number` - The version of the node, optional, defaults to -1.\n* callback(error, stat) `Function` - The callback function. The `stat` is an\n  instance of [`Stat`](#stat).\n\n**Example**\n\n```javascript\nzookeeper.setACL(\n    '/test/demo',\n    [\n        new zookeeper.ACL(\n            zookeeeper.Permission.ADMIN,\n            new zookeeper.Id('ip', '127.0.0.1')\n        )\n    ],\n    function (error, acls, stat) {\n        if (error) {\n            console.log(error.stack);\n            return;\n        }\n\n        console.log('New ACL is set.');\n    }\n);\n```\n\n---\n\n#### Transaction transaction()\n\nCreate and return a new Transaction instance which provides a builder object\nthat can be used to construct and commit a set of operations atomically.\n\nSee [Transaction](#transaction) for details.\n\n\n**Example**\n\n```javascript\nvar transaction = zookeeper.transaction();\n```\n\n---\n\n#### void mkdirp(path, [data], [acls], [mode], callback)\n\nCreate given path in a way similar to `mkdir -p`.\n\n**Arguments**\n\n* path `String` - Path of the node.\n* data `Buffer` - The data buffer, optional, defaults to `null`.\n* acls `Array` - An array of [ACL](#acl) objects, optional, defaults to\n  `ACL.OPEN_ACL_UNSAFE`\n* mode `CreateMode` -  The creation mode, optional, defaults to\n  `CreateMode.PERSISTENT`\n* callback(error, path) `Function` - The callback function.\n\n**Example**\n\n```javascript\nzookeeper.mkdirp('/test/demo/1/2/3', function (error, path) {\n    if (error) {\n        console.log(error.stack);\n        return;\n    }\n\n    console.log('Node: %s is created.', path);\n});\n```\n\n---\n\n#### void addAuthInfo(scheme, auth)\n\nAdd the specified scheme:auth information to this client.\n\n**Arguments**\n\n* scheme `String` - The authentication scheme.\n* auth `Buffer` - The authentication data buffer.\n\n**Example**\n\n```javascript\nzookeeper.addAuthInfo('ip', Buffer.from('127.0.0.1'));\n```\n\n---\n\n#### State getState()\n\nReturn the current client [state](#state).\n\n**Example**\n\n```javascript\nvar client = zookeeper.createClient({...});\nvar state = client.getState();\nconsole.log('Current state is: %s', state);\n```\n\n---\n\n#### Buffer getSessionId()\n\nReturns the session id of this client instance. The value returned is not valid\nuntil the client connects to a server and may change after a re-connect.\n\nThe id returned is a long integer stored into a 8 bytes\n[`Buffer`](http://nodejs.org/api/buffer.html) since Javascript does not support\nlong integer natively.\n\n**Example**\n\n```javascript\nvar client = zookeeper.createClient({...});\nvar id = client.getSessionId();\nconsole.log('Session id is: %s', id.toString('hex'));\n```\n\n---\n\n#### Buffer getSessionPassword()\n\nReturns the session password of this client instance. The value returned is not\nvalid until the client connects to a server and may change after a re-connect.\n\nThe value returned is an instance of\n[`Buffer`](http://nodejs.org/api/buffer.html).\n\n**Example**\n\n```javascript\nvar client = zookeeper.createClient({...});\nvar pwd = client.getSessionPassword();\n```\n\n---\n\n#### Number getSessionTimeout()\n\nReturns the *negotiated* session timeout (in milliseconds) for this client\ninstance. The value returned is not valid until the client connects to a server\nand may change after a re-connect.\n\n**Example**\n\n```javascript\nvar client = zookeeper.createClient({...});\nvar sessionTimeout = client.getSessionTimeout();\n```\n\n---\n\n### State\n\nAfter the `connect()` method is invoked, the ZooKeeper client starts its\nlife cycle and transitions its state as described in the following diagram.\n\n![state transition](http://zookeeper.apache.org/doc/r3.4.5/images/state_dia.jpg)\n\nThere are two ways to watch the client state changes:\n\n1\\. **Node.js convention:** Register event listener on the specific event\nwhich interests you. The following is the list of events that can be watched:\n\n* `connected` - Client is connected and ready.\n* `connectedReadOnly` - Client is connected to a readonly server.\n* `disconnected` - The connection between client and server is dropped.\n* `expired` - The client session is expired.\n* `authenticationFailed` - Failed to authenticate with the server.\n\nNote: some events (e.g. `connected` or `disconnected`) maybe be emitted more\nthan once during the client life cycle.\n\n**Example**\n\n```javascript\nclient.on('connected', function () {\n    console.log('Client state is changed to connected.');\n});\n```\n\n2\\. **Java client convention:** Register one event listener on the `state` event\nto watch all state transitions. The listener callback will be called with an\ninstance of the `State` class. The following is the list of exported state\ninstances:\n\n* `State.CONNECTED` - Client is connected and ready.\n* `State.CONNECTED_READ_ONLY` - Client is connected to a readonly server.\n* `State.DISCONNECTED` - The connection between client and server is dropped.\n* `State.EXPIRED` - The client session is expired.\n* `State.AUTH_FAILED` - Failed to authenticate with the server.\n\n```javascript\nclient.on('state', function (state) {\n    if (state === zookeeper.State.SYNC_CONNECTED) {\n        console.log('Client state is changed to connected.');\n    }\n});\n```\n\n---\n\n### Event\n\nOptionally, you can register watcher functions when calling\n[`exists`](#void-existspath-watcher-callback),\n[`getChildren`](#void-getchildrenpath-watcher-callback) and\n[`getData`](#void-getdatapath-watcher-callback) methods. The watcher function\nwill be called with an instance of `Event`.\n\n**Properties**\n\nThere are four type of events are exposed as `Event` class properties.\n\n* `NODE_CREATED` - Watched node is created.\n* `NODE_DELETED` - watched node is deleted.\n* `NODE_DATA_CHANGED` - Data of watched node is changed.\n* `NODE_CHILDREN_CHANGED` - Children of watched node is changed.\n\n---\n\n#### Number getType()\n\nReturn the type of the event.\n\n---\n\n#### String getName()\n\nReturn the name of the event.\n\n---\n\n#### Number getPath()\n\nReturn the path of the event.\n\n---\n\n#### String toString()\n\nReturn a string representation of the event.\n\n---\n\n### Transaction\n\nTransaction provides a builder interface to construct and commit a set of\noperations atomically.\n\n**Example**\n\n```javascript\nvar client = zookeeper.createClient(process.argv[2] || 'localhost:2181');\n\nclient.once('connected', function () {\n    client.transaction().\n        create('/txn').\n        create('/txn/1', Buffer.from('transaction')).\n        setData('/txn/1', Buffer.from('test'), -1).\n        check('/txn/1').\n        remove('/txn/1', -1).\n        remove('/txn').\n        commit(function (error, results) {\n            if (error) {\n                console.log(\n                    'Failed to execute the transaction: %s, results: %j',\n                    error,\n                    results\n                );\n\n                return;\n            }\n\n            console.log('Transaction completed.');\n            client.close();\n        });\n});\n\nclient.connect();\n```\n\n#### Transaction create(path, [data], [acls], [mode])\n\nAdd a create operation with given path, data, acls and mode.\n\n**Arguments**\n\n* path `String` - Path of the node.\n* data `Buffer` - The data buffer, optional, defaults to null.\n* acls `Array` - An array of [ACL](#acl) objects, optional, defaults to\n  `ACL.OPEN_ACL_UNSAFE`\n* mode `CreateMode` -  The creation mode, optional, defaults to\n  `CreateMode.PERSISTENT`\n\n---\n\n#### Transaction setData(path, data, [version])\n\nAdd a set-data operation with the given path, data and optional version.\n\n**Arguments**\n\n* path `String` - Path of the node.\n* data `Buffer` - The data buffer, or null.\n* version `Number` - The version of the node, optional, defaults to -1.\n\n---\n\n#### Transaction check(path, [version])\n\nAdd a check (existence) operation with given path and optional version.\n\n**Arguments**\n\n* path `String` - Path of the node.\n* version `Number` - The version of the node, optional, defaults to -1.\n\n---\n\n#### Transaction remove(path, data, version)\n\nAdd a delete operation with the given path and optional version.\n\n**Arguments**\n\n* path `String` - Path of the node.\n* version `Number` - The version of the node, optional, defaults to -1.\n\n---\n\n#### void commit(callback)\n\nExecute the transaction atomically.\n\n**Arguments**\n\n* callback(error, results) `Function` - The callback function.\n\n---\n\n### Exception\n\nIf the requested operation fails due to reason related to ZooKeeper, the error\nwhich is passed into callback function will be an instance of `Exception` class.\n\nThe exception can be identified through its error code, the following is the\nlist of error codes that are exported through `Exception` class.\n\n* `Exception.OK`\n* `Exception.SYSTEM_ERROR`\n* `Exception.RUNTIME_INCONSISTENCY`\n* `Exception.DATA_INCONSISTENCY`\n* `Exception.CONNECTION_LOSS`\n* `Exception.MARSHALLING_ERROR`\n* `Exception.UNIMPLEMENTED`\n* `Exception.OPERATION_TIMEOUT`\n* `Exception.BAD_ARGUMENTS`\n* `Exception.API_ERROR`\n* `Exception.NO_NODE`\n* `Exception.NO_AUTH`\n* `Exception.BAD_VERSION`\n* `Exception.NO_CHILDREN_FOR_EPHEMERALS`\n* `Exception.NODE_EXISTS`\n* `Exception.NOT_EMPTY`\n* `Exception.SESSION_EXPIRED`\n* `Exception.INVALID_CALLBACK`\n* `Exception.INVALID_ACL`\n* `Exception.AUTH_FAILED`\n\n**Example**\n\n```javascript\nzookeeper.create('/test/demo', function (error, path) {\n    if (error) {\n        if (error.getCode() == zookeeper.Exception.NODE_EXISTS) {\n            console.log('Node exists.');\n        } else {\n            console.log(error.stack);\n        }\n        return;\n    }\n\n    console.log('Node: %s is created.', path);\n});\n```\n\n#### Number getCode()\n\nReturn the error code of the exception.\n\n---\n\n#### String getPath()\n\nReturn the associated node path of the exception. The path can be `undefined`\nif the exception is not related to node.\n\n--\n\n#### String getName()\n\nReturn the exception name as defined in aforementioned list.\n\n---\n\n### String toString()\n\nReturn the exception in a readable string.\n\n---\n\n\n## Dependency\n\nThis module depends on the following third-party libraries:\n\n* [async](https://github.com/caolan/async)\n* [underscore](http://underscorejs.org)\n\n## License\n\nThis module is licensed under [MIT License](raw/master/LICENSE)\n","funding_links":[],"categories":["JavaScript","Repository"],"sub_categories":["Distribute"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexguan%2Fnode-zookeeper-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexguan%2Fnode-zookeeper-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexguan%2Fnode-zookeeper-client/lists"}