Gun()
TheGun constructor initializes a new GUN database instance. You can create a local database or connect to peers for distributed synchronization.
Signature
Parameters
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):- Returns existing Gun instance if one is passed
- Handles being called without
newkeyword - Initializes the internal state graph and event system
- Sets up peer connections if specified
Notes
- GUN can be called with or without the
newkeyword - 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