Skip to content
Bo edited this page Jun 5, 2022 · 62 revisions

image

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!

Quickstart guides - Start creating apps with GUN in a few lines


INSTALLATION: https://github.com/amark/gun/wiki/Installation
API: https://github.com/amark/gun/wiki/API

GETTING STARTED on GitHub Wiki https://github.com/amark/gun/wiki/Getting-Started-(v0.3.x)

GETTING STARTED on GUN website (with interactive tutorials) https://gun.eco/docs/

How to run a node - Deploy a GUN relay server everywhere

GUN can be used in browsers, NodeJS, and mobile.


Basically

const GUN = require('gun');
const server = require('http').createServer().listen(8080);
const gun = GUN({web: server});

Browser

Script

The easiest way is to just add GUN into your HTML:

<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
<script>
gun = GUN(); // your code here
</script>

Require

If you are using Webpack or other build tools, first follow the npm install, then add this to your browser code:

const GUN = require('gun/gun');

Import

Same as with require, but using the latest ES6 syntax:

import GUN from "https://cdn.skypack.dev/gun";

Node

First you need to install GUN with NPM or other via the command line:

$npm install gun

Note: If you don't have node or npm installed, read this.

Then add this to your server code:

const GUN = require('gun');

Note: GUN comes with many default NodeJS adapters for storage and networking. If you do not want these, just do require('gun/gun') instead.

HTTP

We recommend using a 1-click deploy instead, or running npm start inside of your local GUN repo. However, if you want to install GUN to an existing HTTP server, just pass it the server instance:

const server = require('http').createServer().listen(8080);
const gun = GUN({web: server});

Please see the HTTP(S) example, or Express in the same folder.

Or using --experimental-modules in NodeJS might make import GUN from './node_modules/gun/lib/server.js' work.

Server with basic example (gun in action)

Start a new repo:

// server.js

;(function(){
  var gun = require('gun/examples/http');
  if(!gun.back){ return } // http example auto spawns subprocess

  var fs = require('fs');
  var server = gun.back('opt.web');
  var route = server.route = {}

  fs.readdir('./route', function(err, dir){
      if(err || !dir){ return }
      dir.forEach(function(file){
          if(!file){ return }
          route[file.split('.')[0]] = require('./route/'+file);
      });
  });
 
// with this line you can type a message on http://localhost:8765/basic/paste.html and check if the server works.
  gun.get('test').on(data => console.log(data))

}());

-npm gun

-npm start

Check if the server works

image image

1-Click Deploy

https://www.heroku.com/deploy/?template=https://github.com/amark/gun

Local-Desktop-Gun-Relay-(Windows,-Linux,-MAC)

https://github.com/amark/gun/wiki/Local-Desktop-Gun-Relay-(Windows,-Linux,-MAC)

Android

https://github.com/amark/gun/wiki/Android

Raspberry Pi

https://github.com/amark/gun/wiki/RaspberryPi

Gun Relay Donation Tool - Taking the dev 1-click-deploy and turning it into a consumer 1-click deploy!

https://github.com/amark/gun/wiki/Gun-Relay-Donation-Tool

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