Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qxip/gun-host
GunDB HTTP/HTTPS Server and API
https://github.com/qxip/gun-host
api gun gundb server
Last synced: 3 months ago
JSON representation
GunDB HTTP/HTTPS Server and API
- Host: GitHub
- URL: https://github.com/qxip/gun-host
- Owner: QXIP
- Created: 2018-01-22T11:46:23.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-15T16:23:30.000Z (almost 7 years ago)
- Last Synced: 2024-05-01T11:33:38.765Z (9 months ago)
- Topics: api, gun, gundb, server
- Language: JavaScript
- Homepage: http://qxip.net
- Size: 6.78 MB
- Stars: 17
- Watchers: 4
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gun-host
It is a lib to run [Gun](http://gun.js.org) host in Node.js1. [Install](#install)
2. [Usage](#usage)
3. [Development](#development)# Install
```
npm install --save https://github.com/QXIP/gun-host
```# Usage
The example illustrates creating cluster node `sentinl`, adding a child node `hosts`, then adding `config.host` node as a child of `hosts`.## Init and start host
```
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: {}
}```
## Add/get data
```
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',
}
}
}
}
```
## Delete data
```
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: {}
}
}
```
# Development
## Install libs
```
npm install -g eslint eslint-config-google nyc
```
## Test
```
npm run rest
```
## Run examples
```
node examples/usage.js
```