Skip to content

Documentation

Documentation

Welcome to the NUTS documentation. Choose a topic to get started:

Quick Start (Without Docker)

  1. Build Caddy with NUTS:

    xcaddy build --with github.com/ideaconnect/nuts
    
  2. Start NATS with JetStream enabled:

    nats-server -js -p 4222
    
  3. Create a JetStream stream:

    nats stream add EVENTS \
      --subjects "events.>" \
      --storage file \
      --retention limits \
      --max-msgs 10000 \
      --max-age 24h \
      --discard old
    
  4. Create a Caddyfile:

    :8080 {
        route /events* {
            uri strip_prefix /events
            nuts {
                nats_url nats://localhost:4222
                stream_name EVENTS
                topic_prefix events.
            }
        }
    }
    
  5. Run Caddy:

    ./caddy run --config Caddyfile
    
  6. Connect from JavaScript:

    const events = new EventSource('/events?topic=my-topic');
    
    events.addEventListener('message', (e) => {
        const data = JSON.parse(e.data);
        console.log('Received:', data, 'ID:', e.lastEventId);
    });
    
  7. Publish a message (using the NATS CLI):

    nats pub events.my-topic '{"hello": "world"}'
    

Quick Start (With Docker)

Pick whichever fits your workflow:

For detailed configuration, client usage, and example scenarios, see the Usage page.

For full build and run instructions, see Building & Running.