Skip to main content
GUN is flexible and can be installed and used across multiple platforms and environments. Choose the installation method that best fits your project.

Browser via CDN

The quickest way to get started is to include GUN directly from a CDN:
The CDN version is approximately 9KB gzipped and includes everything you need to get started.

Include SEA for user authentication

If you need user authentication and encryption, also include SEA:

Include AXE for mesh networking

For advanced peer-to-peer mesh networking:

npm installation

For Node.js projects or modern build tools (Webpack, Vite, etc.), install via npm:
If the npm command doesn’t work, you may need to create the node_modules directory first:
Or use sudo npm install gun depending on your system permissions.

Basic usage in Node.js

ES Module imports

Using with SEA in Node.js

For cryptographic features, you need to install the WebCrypto shim:
Then require both:
The @peculiar/webcrypto package is only needed for Node.js and React Native. Browsers have native WebCrypto support.

Node.js server setup

To create a GUN relay peer server:

Simple HTTP server

Server with options

HTTPS server

You can set environment variables for SSL certificates:

React integration

For React applications, install GUN and require it specifically:
For React, use require('gun/gun') instead of require('gun') to avoid webpack issues.

React Native installation

GUN works with React Native but requires additional setup for crypto support.
1

Install dependencies

2

Set up crypto shim

Create a shim file or import the webcrypto polyfill before using SEA:
3

Use GUN in your components

For detailed React Native setup instructions, see the official React Native docs.

Electron installation

GUN works seamlessly with Electron applications:
In your Electron renderer process:
For examples, check out the Electron test repository.

Framework integrations

GUN has community-maintained integrations for popular frameworks:

Vue.js

See vue-gun for integration details.

Svelte

Check out the Svelte documentation for integration guides.

Angular

Install GUN and create a service:
See the Angular example for a complete setup.

Configuration options

When initializing GUN, you can pass various configuration options:
By default, GUN uses localStorage in browsers and file storage in Node.js. You can customize storage adapters as needed.

Deploy a relay peer

GUN includes several deployment options for relay peers:

Heroku

Deploy to Heroku Or manually:
Heroku’s free tier deletes data every 15 minutes. Consider adding persistent storage with Amazon S3.

Docker

Pull from Docker Hub:
Or build locally:
Then visit http://localhost:8765 in your browser.
The Docker image is community-contributed and may have different version numbers. Check the tags to ensure you’re using the latest version.

Linux server

SSH into your server and run the installation script:
Always review installation scripts before running them. You can view install.sh on GitHub first.
Set environment variables as needed:
You can safely press CTRL+A+D to detach without stopping the peer. To stop everything: killall screen or killall node.

Dome

Deploy with one click using Dome: Deploy to Dome

Zeet

Deploy using Zeet: Deploy to Zeet

Production deployment notes

For production deployments, consider the following:
1

Use a process manager

Use pm2 or similar to keep your relay peer running after server reboots:
2

Configure reverse proxy

Use nginx or another reverse proxy for SSL termination and load balancing. See the nginx configuration example.
3

Set environment variables

Configure your deployment with appropriate environment variables:
  • PORT - Server port
  • PEERS - Comma-separated list of peer URLs
  • HTTPS_KEY and HTTPS_CERT - SSL certificate paths
4

Disable CI warnings

If deploying a web app using GUN on a cloud provider, set CI=false in your .env to prevent GUN warnings from being treated as build errors.
When deploying, the default examples CDN-ify all GUN files and modules. Moving forward, AXE may automatically cluster your peer into a shared DHT. You may want to disable this to run an isolated network.

Testing your installation

After installing GUN, verify it works:
To run the test suite: npm install -g mocha then npm test in the GUN directory. Note that tests trigger persistent writes, so you’ll need to clear the database (rm -rf *data*) before running tests again.

Troubleshooting

Module not found errors

If you see module errors with React or Webpack:

SEA/Crypto errors in Node.js

Install the WebCrypto polyfill:

Build errors in cloud deployments

Add to your .env file:
Or modify your webpack config to exclude GUN dependencies from builds.

Port already in use

Change the port in your configuration:

Package information

Version

0.2020.1239

Bundle size

~9KB gzipped

Node.js support

= 0.8.4

License

Zlib / MIT / Apache 2.0

Dependencies

  • Required: ws (WebSocket support for Node.js)
  • Optional: @peculiar/webcrypto (for SEA in Node.js/React Native)

Next steps

Now that GUN is installed:

Quickstart guide

Build your first GUN application

API reference

Explore the complete API documentation

Examples

Browse real-world example applications

Community

Join the GUN community chat