DurableObjectNamespace
Creates a Durable Object namespace binding for stateful objects in Cloudflare Workers.
Props
Name of the class that implements the Durable Object.const rooms = DurableObjectNamespace("chat-rooms", {
className: "ChatRoom"
});
Name of the script containing the Durable Object implementation.
Bound to the worker that includes this namespace in its bindings
Environment name for the Durable Object.
Whether to enable SQLite storage for the Durable Object.const users = DurableObjectNamespace("user-store", {
className: "User",
sqlite: true
});
Output
The ID of the Durable Object namespace.
Name of the class that implements the Durable Object.
Name of the script containing the Durable Object implementation.
Type identifier for the binding.
Examples
Basic Durable Object Namespace
const rooms = DurableObjectNamespace("chat-rooms", {
className: "ChatRoom"
});
const worker = await Worker("chat", {
entrypoint: "./src/chat.ts",
bindings: {
ROOMS: rooms
}
});
Durable Object with SQLite
const users = DurableObjectNamespace("user-store", {
className: "User",
sqlite: true
});
const worker = await Worker("api", {
entrypoint: "./src/api.ts",
bindings: {
USERS: users
}
});
Cross-Script Binding
const dataWorker = await Worker("data-worker", {
entrypoint: "./src/data.ts",
bindings: {
STORAGE: DurableObjectNamespace("storage", {
className: "DataStorage"
})
}
});
const apiWorker = await Worker("api-worker", {
entrypoint: "./src/api.ts",
bindings: {
SHARED_STORAGE: dataWorker.bindings.STORAGE
}
});