forked from cilliemalan/node-zookeeper-client-async
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
35 lines (26 loc) · 1.04 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const zk = require('.');
(async function main() {
const client = zk.createAsyncClient("127.0.0.1:2181");
// connect to the server
await client.connectAsync();
console.log('connected!');
// create a node
const rootPath = await client.mkdirpAsync('/test');
console.log(`created ${rootPath}`)
// add some ephemeral nodes
await client.createAsync('/test/counter-', Buffer.from('first'), null, zk.CreateMode.EPHEMERAL_SEQUENTIAL);
await client.createAsync('/test/counter-', Buffer.from('second'), null, zk.CreateMode.EPHEMERAL_SEQUENTIAL);
// list the nodes
const nodes = await client.getChildrenAsync('/test');
// print stuff to console
console.log(`${rootPath} has the children:`)
await Promise.all(nodes.map(async node => {
const data = await client.getDataAsync(`/test/${node}`);
console.log(` ${node}: ${data.data}`);
}));
// delete everything
await client.rmrfAsync(rootPath);
// shut down
await client.closeAsync();
console.log('disconnected');
})();