-
Notifications
You must be signed in to change notification settings - Fork 55
/
basic-argv.js
38 lines (30 loc) · 955 Bytes
/
basic-argv.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
36
37
38
/*
* This is the most basic example of using Discover.
*
* In this example all we are interested in is when new nodes are added to the
* network or when they are removed. The master selection stuff happens behind
* the scenes but we can completely ignore it and just handle the events for
* new nodes added or removed from the network.
*
*/
var argv = require('optimist').argv;
var Discover = require("../");
delete argv._;
delete argv.$0;
var d = new Discover(argv);
console.log('d.me:' , d.me);
console.log('instanceUuid', d.broadcast.instanceUuid);
console.log('processUuid', d.broadcast.processUuid);
d.advertise({ testing : Math.random() });
d.on("added", function (obj) {
console.log("New node added to the network.");
console.log(obj);
});
d.on("removed", function (obj) {
console.log("Node removed from the network.");
console.log(obj);
});
d.on("error", function (err) {
console.log("error", err);
});
module.exports = d;