-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
hub.js
Hector edited this page Aug 25, 2021
·
6 revisions
The hub feature is an optional feature that allows you to watch a directory and upload all of its content on the database (only text files are supported for now).
First, you must install Chokidar
. When it’s done, import hub.js
:
const hub = require('gun/lib/hub'); // Classic
// or
import hub from ‘gun/lib/hub’; // ES6’s way
// then
hub.watch(/* The path you want to watch. */)
what
(String) - Which directory hub
should watch.
options
(Object) - Change the behavior of hub.
// Available options
{
msg: true // or false | disable or enable update messages,
hubignore: false // or true | Activate the .hubignore feature
}
The purpose of the .hubignore
is to give you the possibility to choose what files are watched by hub & sent to Gun ! It works exactly as the .gitignore
file. It must be in the root of the folder you're watching.
# Very important API KEY !
/whatever/api-key.txt
.
├── index.html
├── .hubignore
└── whatever/
└── api-key.txt
Given this directory :
.
└── directory/
├── index.html
├── .hubignore
└── whatever/
├── style.css
└── api-key.txt
// Basic usage.
const hub = require(‘gun/lib/hub’); // OR import hub from ‘gun/lib/hub’;
hub.watch(‘./directory’);
gun.get(‘hub’).on(data => {
console.log(data[‘/directory/index.html’]) // Get the content of index.html
console.log(data[‘/directory/folder/whatever.css’]) // Get the content of whatever.css
})
# .hubignore
/whatever/api-key.txt # Won't be uploaded !