-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Installation
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.
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...
The easiest way is to just include Gun in the <head>
tag of your index.html
page:
<script src="https://cdn.jsdelivr.net/npm/gun/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.
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/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.
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 from 'gun/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.
First you need to install Gun with NPM or Yarn:
$ 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.