Skip to main content

Gun()

The Gun constructor initializes a new GUN database instance. You can create a local database or connect to peers for distributed synchronization.

Signature

Parameters

object | string | array
Configuration options for the GUN instance. Can be an object with options, a peer URL string, or an array of peer URLs.

Return Value

Returns a GUN chain reference that can be used to read and write data.

Examples

Local Database

Single Peer

Multiple Peers

Node.js with RAD Storage

Implementation Details

From the source code (root.js:4-8):
The constructor:
  1. Returns existing Gun instance if one is passed
  2. Handles being called without new keyword
  3. Initializes the internal state graph and event system
  4. Sets up peer connections if specified

Notes

  • GUN can be called with or without the new keyword
  • All data is automatically synchronized across connected peers
  • The constructor returns immediately; peer connections are established asynchronously
  • Each Gun instance maintains an in-memory graph for fast reads