Skip to content
Robert Heessels edited this page Feb 5, 2018 · 20 revisions

Gun can be installed and used in both browser (client side) and server applications. We have made it very easy to be be used in different environments.

In the browser / client side

Here a three different ways to include Gun in your browser application:

  • Include as script tag
  • Require
  • Import (ES6)

Just pick your favorite way of including scripts...

Include as script tag

The easiest way is to just include Gun in the <head> tag of your index.html page:

<script src="https://cdn.rawgit.com/amark/gun/master/gun.js"></script>

And you can then test it by adding this to your index.html:

<script>
  var gun = Gun()
  var greetings = gun.get('greetings')
  greetings.put({hello: 'world'})
  greetings.on(function (data) {
    console.log('Update!', data)
  })
</script>

Now you should see the message in the browser console.

Require

Another way to include Gun in your browser app is with require.

First you need to install Gun with NPM or Yarn:

$ npm install gun

or

$ yarn add gun

Then require Gun in your script:

var Gun = require('gun');

And test it like this:

  var gun = Gun()
  var greetings = gun.get('greetings')
  greetings.put({hello: 'world'})
  greetings.on(function (data) {
    console.log('Update!', data)
  })

After running you should see the message in the browser console.

Import (ES6)

Similar to require you can include Gun with import.

First you need to install Gun with NPM or Yarn:

$ npm install gun

or

$ yarn add gun

Then import Gun in your script:

import 'gun'

And test it like this:

  var gun = Gun()
  var greetings = gun.get('greetings')
  greetings.put({hello: 'world'})
  greetings.on(function (data) {
    console.log('Update!', data)
  })

After running you should see the message in the browser console.

Note that right now, even though you import, Gun is defined and used as a global variable.

On the server (Node.js)

First you need to install Gun with NPM or Yarn:

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

$ npm install gun

or

$ yarn add gun

Then require Gun in your script hello.js:

var Gun = require('gun');

For testing add to hello.js:

  var gun = Gun()
  var greetings = gun.get('greetings')
  greetings.put({hello: 'world'})
  greetings.on(function (data) {
    console.log('Update!', data)
  })

Then run the script:

$ node ./hello.js

After running you should see the message in the console output.

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