All recipes
Recipes live inside their pillar in the sidebar — each area's Recipes section sits below the guides that teach the basics it assumes. This page is the cross-area index: every recipe in the docs, grouped by pillar, so you can scan the whole catalog in one place. Each one is goal-first — it starts from a concrete intent and ends with a command that proves the change works.
Preferred NetScript paths
Start with the framework-owned path below. The lower-level alternatives remain useful when you need to integrate an existing host, but they should not be the first construction you copy into a NetScript workspace.
| Task | Preferred path | Why this path comes first |
|---|---|---|
| Load data for a typed page | definePage().withResource(...) |
Keeps route data in the page builder instead of recreating an Express-style loader. |
| Keep island data live | useLiveQuery |
Uses the package-owned query bridge, hydration, and cleanup rather than a hand-rolled polling loop. |
| Add or customize UI | netscript ui:add |
Copies registry source and its token-driven styles into the app you own. |
| Deploy to Google Cloud | netscript deploy cloud-run |
Uses the first-class target lifecycle (plan, up, down) instead of an unrelated deployment wrapper. |
| Back TanStack DB with a service | @netscript/sdk/collections |
Builds the collection from the typed service/query surface. |
| Connect a typed client to TanStack Query | @netscript/sdk/query-client |
Supplies NetScript query keys, invalidation, persistence, and service utilities. |
| Add server-side stale-while-revalidate caching | CacheQuery from @netscript/sdk/cache |
Uses the SDK cache engine and its provider boundary rather than a parallel cache contract. |
| Publish interactive API documentation | Scalar/OpenAPI | One service option exposes the contract-derived spec and the bundled Scalar UI. |
The linked recipe or guide is the canonical sample. When it also shows a general-purpose construction, that alternative is an integration escape hatch, not the default NetScript route.
Web Layer
- Customize the Fresh UI —
bring the dashboard components into your workspace with
ui:init/ui:addand edit them directly. - Build a server-validated form —
route-bound form state, server validation, mutation, and success handling in
one typed page definition with
definePage().withForm(). - Build a desktop frontend — one Fresh frontend that runs as an ordinary browser app and gains native capabilities on the desktop.
Services & SDK
- Add a service — run
netscript service add --name <service> --with-clientto define a typed contract, generateapps/<app>/lib/<service>.ts, implement the handlers, and confirm the service answers on/api/rpc/*. - Discover services — call another plugin's or workspace member's typed service without hardcoding its address.
- Expose OpenAPI & Scalar — publish an OpenAPI document and browsable Scalar docs for a service.
Background jobs
- Run a polyglot task — define a non-TypeScript script (Python, shell, .NET, any executable) as a task with a permission sandbox and run it through the executor.
- Tune the worker runtime — trade throughput against isolation with concurrency, runner mode, per-task permissions, and timeouts/retries.
- Restrict worker task permissions —
give every Deno task explicit permissions; an omitted permission object
compiles to
--allow-all. - Add a task runtime adapter — advanced: add a custom runtime adapter to the built-in task executor.
Durable workflows
- Build a validated ingestion queue — a typed queue whose messages are schema-checked before they enter the queue and again before a consumer handles them.
- Publish a durable stream — let server-side state be subscribed to by browsers and other consumers through a durable stream service.
AI & Agents
- Build a durable chat — an AI chat on a Fresh route whose transcript survives reload and reconnect, with one server-side tool.
Data & Persistence
- Database & migration —
initialize, generate, seed, and inspect the Postgres schema with the
netscript dbcommands. - Queue / KV / cron — the reactive
KV store, the durable queue, and cron schedules, including
--unstable-kv. - Choose a queue provider — pick the right queue backend, and either let auto-discovery select one or pin one explicitly.
- Use a second database — add a second Postgres, or a MySQL/SQL Server instance, alongside the default database.
Identity & Access
- Add authentication — install
the official auth plugin, pick one active backend via
NETSCRIPT_AUTH_BACKEND, migrate, and sign in.
Orchestration & Runtime
- Add a plugin — install a first-party plugin, regenerate the registry, and verify the service answers.
- Deploy locally with Aspire — run the full local resource graph from the generated Aspire AppHost.
- Deploy — the portability story: raw
deno taskentry points and the--no-aspireescape hatch when you provision dependencies yourself. - Deploy to Deno Deploy — push a preview, promote to prod, and read status and logs with the first-class deploy command.
- Graceful shutdown — drain
in-flight requests and jobs, run teardown hooks, and close connections on
SIGINT/SIGTERM. - Roll out runtime overrides — change a deployed behavior without rebuilding the workspace.
- Author a plugin — advanced:
build a custom plugin with the same manifest and
mod.tscontract the first-party plugins use. - Deno LSP code intelligence — keep go-to-definition, hover, and diagnostics aligned across CLI and editors.
Observability
- Add OpenTelemetry — emit
custom spans and structured logs, propagate
traceparent, and read the traces in the Aspire dashboard.
Not sure which recipe you want? Name the outcome first. "Users must sign in" → Add authentication. "This event should fan out to a background job" → Add a plugin. "It has to run where there is no Aspire" → Deploy. The recipes are deliberately small and composable; most real features chain two or three of them.