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 Or use
node_modules directory first: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:Node.js server setup
To create a GUN relay peer server:Simple HTTP server
Server with options
HTTPS server
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:Framework integrations
GUN has community-maintained integrations for popular frameworks:Vue.js
Svelte
Check out the Svelte documentation for integration guides.Angular
Install GUN and create a service: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
Docker
Pull from Docker Hub: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:CTRL+A+D to detach without stopping the peer. To stop everything: killall screen or killall node.
Dome
Deploy with one click using Dome:Zeet
Deploy using 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 portPEERS- Comma-separated list of peer URLsHTTPS_KEYandHTTPS_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.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:
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