@durable-streams/server

中文文档
0.3.9发布于 2026/09/11Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 44.6万

Node.js reference server implementation for Durable Streams

原始使用文档
文档目录11 节
  1. Installation
  2. Overview
  3. Quick Start
  4. Storage Modes
  5. In-Memory (Default)
  6. File-Backed
  7. Lifecycle Hooks
  8. API
  9. DurableStreamTestServer
  10. Testing Your Implementation
  11. License

@durable-streams/server

Node.js reference server implementation for the Durable Streams protocol.

Installation

npm install @durable-streams/server

Overview

This package provides a reference implementation of the Durable Streams protocol for Node.js. It supports both in-memory and file-backed storage modes, making it suitable for development, testing, and prototyping. For production deployments, use the Caddy plugin or Electric Cloud.

For a standalone binary option, see the Caddy-based server.

Quick Start

import { DurableStreamTestServer } from "@durable-streams/server"

const server = new DurableStreamTestServer({
  port: 4437,
  host: "127.0.0.1",
})

await server.start()
console.log("Server running on http://127.0.0.1:4437")

Storage Modes

In-Memory (Default)

Fast, ephemeral storage for development and testing. Omit dataDir to use in-memory:

const server = new DurableStreamTestServer({ port: 4437 })

File-Backed

Persistent storage with streams stored as log files and LMDB for metadata:

const server = new DurableStreamTestServer({
  port: 4437,
  dataDir: "./data/streams",
})

Lifecycle Hooks

Track stream creation and deletion events:

const server = new DurableStreamTestServer({
  port: 4437,
  onStreamCreated: (event) => {
    console.log(`Stream created: ${event.path} (${event.contentType})`)
  },
  onStreamDeleted: (event) => {
    console.log(`Stream deleted: ${event.path}`)
  },
})

API

DurableStreamTestServer

interface TestServerOptions {
  port?: number                          // Default: 4437
  host?: string                          // Default: "127.0.0.1"
  longPollTimeout?: number               // Default: 30000 (ms)
  dataDir?: string                       // File-backed storage; omit for in-memory
  onStreamCreated?: StreamLifecycleHook  // Hook for stream creation
  onStreamDeleted?: StreamLifecycleHook  // Hook for stream deletion
  compression?: boolean                  // Default: true
  cursorIntervalSeconds?: number         // Default: 20
  cursorEpoch?: Date                     // Epoch for cursor calculation
}

class DurableStreamTestServer {
  constructor(options?: TestServerOptions)
  start(): Promise<void>
  stop(): Promise<void>
  readonly port: number
  readonly baseUrl: string
}

## Exports

```typescript
export { DurableStreamTestServer } from "./server"
export { StreamStore } from "./store"
export { FileBackedStreamStore } from "./file-store"
export { encodeStreamPath, decodeStreamPath } from "./path-encoding"
export { createRegistryHooks } from "./registry-hook"
export {
  calculateCursor,
  handleCursorCollision,
  generateResponseCursor,
  DEFAULT_CURSOR_EPOCH,
  DEFAULT_CURSOR_INTERVAL_SECONDS,
  type CursorOptions,
} from "./cursor"
export type {
  Stream,
  StreamMessage,
  TestServerOptions,
  PendingLongPoll,
  StreamLifecycleEvent,
  StreamLifecycleHook,
} from "./types"

Testing Your Implementation

Use the conformance test suite to validate protocol compliance:

import { runConformanceTests } from "@durable-streams/server-conformance-tests"

runConformanceTests({
  baseUrl: "http://localhost:4437",
})

License

Apache-2.0

版本与发布记录

@durable-streams/server 共发布 22 个版本,首次发布于 2025/12/24;过去 12 个月发布了 22 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.9latest2026/09/112 个月前
0.3.82026/07/173 个月前
0.3.72026/06/035 个月前
0.3.62026/06/035 个月前
0.3.52026/06/015 个月前
0.3.42026/05/285 个月前

关于 @durable-streams/server 的常见问题

@durable-streams/server 是什么?

Node.js reference server implementation for Durable Streams

如何安装 @durable-streams/server?

在项目目录运行 npm install @durable-streams/server,或使用 pnpm add / yarn add / bun add。

@durable-streams/server 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@durable-streams/server 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@durable-streams/server 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@durable-streams/server 可以商用吗?

@durable-streams/server 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@durable-streams/server 的下载量有多少?

根据 npm 官方下载统计,@durable-streams/server 在 2026/10/13 – 2026/11/11 这 30 天内被下载 445,653 次,日均约 14,855 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@durable-streams/server 还在维护吗?

最新版本 0.3.9 发布于 2026/09/11(2 个月前);至今共发布 22 个版本,其中过去 12 个月发布了 22 个;首次发布于 2025/12/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。