Skip to content
Hector edited this page Aug 25, 2021 · 6 revisions

lib/hub.js (server-side only)

Host your website on Gun !

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).

How to use it ?

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. */)

Options

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 .hubignore file

It'd be really dangerous if you upload all your files on the DB !

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

Example

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 !

This wiki is where all the GUN website documentation comes from.

You can read it here or on the website, but the website has some special features like rendering some markdown extensions to create interactive coding tutorials.

Please feel free to improve the docs itself, we need contributions!

Clone this wiki locally