-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Installation
GUN can be used in both browsers and servers. We have made it easy to install in many different environments.
There are a couple choices:
The easiest is to just add GUN into your HTML:
<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
<script>
// your code here
</script>
Assuming you are using something like Webpack or Browserify, first follow the npm install, then add this to your browser code:
var Gun = require('gun/gun');
Same as with require
, but using the latest ES6 syntax:
import Gun from 'gun/gun'
Note: For now, even though you import it, GUN is still defined and used as a global variable.
First you need to install GUN with NPM or Yarn via the command line:
$npm install gun
or $yarn add gun
Then add this to your server code:
var 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.
If you want to actually install GUN to a server, you need to pass it an HTTP instance:
var server = require('http').createServer().listen(8080);
var gun = Gun({web: server});
We recommend you check out the default HTTP(S) example, or the Express and Hapi ones in the same folder.
- Try out the Hello World.
- Watch the 2 minute Crash Course?
- Hands-on learn answers to all your questions in THE INTERACTIVE TUTORIAL!
In Node 12, if you use the --experimental-modules flag, you can use Import Gun from './node_modules/gun/lib/server.js' and that will do the trick for those of us who want to use ESM modules