Browse documentation

ServerStorage

Provides request-scoped browser-like storage during server rendering.

Table of contents

Category

Value

Import

js
import { ServerStorage } from "valyrian.js/node";

Public signature

ts
ServerStorage.run<T>(callback: () => T): T

API form

ServerStorage is a class with a static request-boundary method. Use ServerStorage.run(...) around each complete server request. Inside that callback, global sessionStorage and localStorage use the active isolated storage context.

Static methods

ts
ServerStorage.run<T>(callback: () => T): T
ServerStorage.isContextActive(): boolean

Storage surface inside a request

ts
length: number
clear(): void
getItem(key: string): string | null
key(index: number): string | null
removeItem(key: string): void
setItem(key: string, value: string): void
toJSON(): Record<string, string>

Request isolation

ServerStorage.run preserves its context through synchronous and asynchronous work returned by the callback. Wrap the full request lifecycle so concurrent requests do not share storage values.