It is a lib to run Gun host in Node.js
npm install --save https://github.com/QXIP/gun-host
The example illustrates creating cluster node sentinl
, adding a child node hosts
, then adding config.host
node as a child of hosts
.
const GunHost = require('gun-host');
const config = {
enabled: true,
name: 'sentinl',
priority_for_master: 0,
absent_time_for_delete: 86400,
absent_time: 15,
loop_delay: 5,
cert: {
selfsigned: true,
valid: 10,
key: null, // full sys path to pem key file
cert: null, // full sys path to cert file
},
gun: {
port: 9000,
host: '0.0.0.0',
cache: 'data.json',
peers: ['https://localhost:9000/gun'],
},
host: {
id: '123',
name: 'velociraptor',
priority: 0,
node: 'hosts',
},
};
const node = new GunHost({
peers: config.gun.peers,
rootNodeName: config.name,
});
const main = async function() {
try {
let resp = await node.start({
host: config.gun.host,
port: config.gun.port,
cache: config.gun.cache,
cert: config.cert,
});
console.log('1. Start server:', resp);
resp = await node.add(`${config.host.node}.${config.host.id}`, config.host);
console.log('2. Add node:', resp);
resp = await node.get(config.host.node);
console.log('3. Get node:', resp);
} catch (err) {
console.error(err);
}
};
main();
Gun holds
root: {
senitnl: {}
}
const addData = async function() {
try {
resp = await node.add(`${config.host.node}.${config.host.id}`, config.host);
console.log('2. Add node:', resp);
resp = await node.get(config.host.node);
console.log('3. Get node:', resp);
} catch (err) {
console.error(err);
}
};
addData();
Gun holds
root: {
setninl: {
hosts: {
'123': {
id: '123',
name: 'velociraptor',
priority: 0,
node: 'hosts',
}
}
}
}
const delete = async function() {
try {
resp = await node.delete(`${config.host.node}.${config.host.id}`);
console.log('4. Delete node:', resp);
resp = await node.get(config.host.node);
console.log('5. Check if node exists after removing', resp);
} catch (err) {
console.error(err);
}
};
delete();
Gun holds
root: {
setninl: {
hosts: {}
}
}
npm install -g eslint eslint-config-google nyc
npm run rest
node examples/usage.js