Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/durable-streams/durable-streams/llms.txt

Use this file to discover all available pages before exploring further.

Installation

Durable Streams provides client libraries for multiple languages and platforms, plus a production-ready server.

Client Libraries

Choose your language:

npm packages

# Client library (read/write)
npm install @durable-streams/client

# CLI tool
npm install -g @durable-streams/cli

# Reference server (development only)
npm install @durable-streams/server

Usage

import { DurableStream, IdempotentProducer } from "@durable-streams/client"

// Create a stream
const stream = await DurableStream.create({
  url: "https://your-server.com/v1/stream/my-stream",
  contentType: "application/json",
})

// Write with idempotent producer
const producer = new IdempotentProducer(stream, "my-service-1", {
  autoClaim: true,
})

for (const event of events) {
  producer.append(JSON.stringify(event))
}

await producer.flush()
await producer.close()

// Read the stream
const res = await stream.stream({ live: false })
const items = await res.json()
console.log(items)

Browser Support

The TypeScript client works in all modern browsers:
  • Chrome 90+
  • Firefox 88+
  • Safari 15+
  • Edge 90+

Node.js Support

  • Node.js 18+
  • Deno 1.30+
  • Bun 1.0+

Server Installation

Durable Streams provides two server implementations:

Binary Downloads

Download the production Caddy-based server from GitHub releases.Available for:
  • macOS (Intel & ARM)
  • Linux (AMD64 & ARM64)
  • Windows (AMD64)

Quick Start

# Download the binary for your platform
wget https://github.com/durable-streams/durable-streams/releases/latest/download/durable-streams-server-linux-amd64

# Make it executable
chmod +x durable-streams-server-linux-amd64

# Start the server
./durable-streams-server-linux-amd64 dev
The server runs on http://localhost:4437 by default.

Configuration

Create a Caddyfile for production configuration:
Caddyfile
{
    order durable_streams before reverse_proxy
}

:4437 {
    durable_streams {
        prefix /v1/stream/
        store file {
            dir ./streams-data
        }
    }
}
Start with the config:
./durable-streams-server run --config Caddyfile

Storage Backends

The Caddy server supports multiple storage backends:
durable_streams {
    store file {
        dir ./streams-data
    }
}
  • ✅ Simple, no external dependencies
  • ✅ Good for development and single-server deployments
  • ❌ Not suitable for multi-server deployments
durable_streams {
    store memory
}
  • ✅ Fast
  • ✅ Good for testing
  • ❌ Data lost on restart
  • ❌ Limited by RAM

Docker

docker pull ghcr.io/durable-streams/server:latest
docker run -p 4437:4437 ghcr.io/durable-streams/server:latest

Environment Variables

  • PORT - Server port (default: 4437)
  • HOST - Bind address (default: 0.0.0.0)
  • STREAMS_DIR - Storage directory for file backend (default: ./streams-data)

CLI Tool

The CLI is useful for testing, debugging, and scripting:

Installation

# Global installation
npm install -g @durable-streams/cli

# Or run directly with npx
npx @durable-streams/cli create my-stream

Usage

1

Set the server URL

export STREAM_URL=http://localhost:4437
2

Create a stream

durable-stream create my-stream
3

Write data

# Write directly
durable-stream write my-stream "Hello, world!"

# Pipe from stdin
echo '{"message": "hello"}' | durable-stream write my-stream --json

# From a file
cat data.json | durable-stream write my-stream --json
4

Read data

# Read all data
durable-stream read my-stream

# Follow live (like tail -f)
durable-stream read my-stream --live
5

Delete a stream

durable-stream delete my-stream

Authentication

# Using environment variable
export STREAM_AUTH="Bearer my-token"
durable-stream read my-stream

# Using --auth flag
durable-stream --auth "Bearer my-token" read my-stream

Options

  • --content-type <type> - Set Content-Type for writes
  • --json - Shorthand for --content-type application/json
  • --live - Follow stream for live updates
  • --auth <value> - Set Authorization header

Platform-Specific Guides

Installation

npm install @durable-streams/client

React Hook Example

import { useEffect, useState } from "react"
import { DurableStream } from "@durable-streams/client"

function useStream<T>(url: string) {
  const [items, setItems] = useState<T[]>([])
  const [error, setError] = useState<Error | null>(null)

  useEffect(() => {
    const stream = new DurableStream({ url })
    
    const start = async () => {
      try {
        const res = await stream.stream<T>({ live: "auto" })
        res.subscribeJson(async (batch) => {
          setItems(prev => [...prev, ...batch.items])
        })
      } catch (err) {
        setError(err as Error)
      }
    }

    start()
  }, [url])

  return { items, error }
}

// Usage
function MyComponent() {
  const { items, error } = useStream("/v1/stream/events")

  if (error) return <div>Error: {error.message}</div>
  
  return (
    <ul>
      {items.map((item, i) => (
        <li key={i}>{JSON.stringify(item)}</li>
      ))}
    </ul>
  )
}

Installation

npm install @durable-streams/client

Usage

import { DurableStream } from "@durable-streams/client"
import { useEffect, useState } from "react"
import { View, Text, FlatList } from "react-native"

export default function StreamScreen() {
  const [items, setItems] = useState([])

  useEffect(() => {
    const stream = new DurableStream({
      url: "https://api.example.com/v1/stream/events",
    })

    const start = async () => {
      const res = await stream.stream({ live: "auto" })
      res.subscribeJson(async (batch) => {
        setItems(prev => [...prev, ...batch.items])
      })
    }

    start()
  }, [])

  return (
    <FlatList
      data={items}
      renderItem={({ item }) => <Text>{JSON.stringify(item)}</Text>}
    />
  )
}
Ensure your React Native version supports fetch and AbortController. React Native 0.70+ has full support.

Installation

npm install @durable-streams/client

Worker Example

import { DurableStream } from "@durable-streams/client"

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    // Create a stream
    const stream = await DurableStream.create({
      url: `${env.STREAM_URL}/v1/stream/events`,
      headers: {
        Authorization: `Bearer ${env.STREAM_TOKEN}`,
      },
      contentType: "application/json",
    })

    // Append event
    await stream.append({
      type: "request",
      path: new URL(request.url).pathname,
      timestamp: Date.now(),
    })

    return new Response("Event logged")
  },
}

Installation

npm install @durable-streams/client

Edge Function Example

import { DurableStream } from "@durable-streams/client"

export const config = {
  runtime: "edge",
}

export default async function handler(req: Request) {
  const stream = new DurableStream({
    url: process.env.STREAM_URL!,
    headers: {
      Authorization: `Bearer ${process.env.STREAM_TOKEN}`,
    },
  })

  await stream.append({
    event: "page_view",
    path: new URL(req.url).pathname,
  })

  return new Response("OK")
}

Installation

import { DurableStream } from "npm:@durable-streams/client"

Usage

import { DurableStream } from "npm:@durable-streams/client"

const stream = await DurableStream.create({
  url: "http://localhost:4437/v1/stream/my-stream",
  contentType: "application/json",
})

await stream.append({ message: "hello from Deno" })

const res = await stream.stream({ live: false })
const items = await res.json()
console.log(items)

Installation

bun add @durable-streams/client

Usage

import { DurableStream } from "@durable-streams/client"

const stream = await DurableStream.create({
  url: "http://localhost:4437/v1/stream/my-stream",
  contentType: "application/json",
})

await stream.append({ message: "hello from Bun" })

const res = await stream.stream({ live: false })
const items = await res.json()
console.log(items)

Verification

To verify your installation:
1

Check server is running

curl http://localhost:4437/health
Expected response:
{"status": "ok"}
2

Create a test stream

curl -X PUT http://localhost:4437/v1/stream/test \
  -H "Content-Type: application/json"
3

Write and read data

# Write
curl -X POST http://localhost:4437/v1/stream/test \
  -H "Content-Type: application/json" \
  -d '{"message": "hello"}'

# Read
curl "http://localhost:4437/v1/stream/test?offset=-1"
If all steps succeed, your installation is complete!

Next Steps

Quick Start Guide

Build your first streaming application

API Reference

Explore the complete API documentation

Protocol Specification

Learn about the protocol internals

Examples

See example applications