Nue sites are static by default, but you can add dynamic behavior by placing server routes inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nuejs/nue/llms.txt
Use this file to discover all available pages before exploring further.
@shared/server/. These routes use the same Request / Response web-platform APIs that edge runtimes expose, so the code you write locally runs unchanged on Cloudflare Workers, Deno Deploy, or any other edge environment. Nue loads your routes automatically during development and preview, routing matching requests to your handlers while serving all other traffic as static files.
Where server routes live
Server routes go in the@shared/server/ directory at your project root. Nue’s worker picks up @shared/server/index.js as the entry point:
@shared/ directory is excluded from the static build — its contents never appear in .dist/.
You can override the default directory with the server key in site.yaml:
Registering routes
Routes are registered using thenue-edgeserver package, which provides a small routing layer on top of the standard Request / Response APIs:
Request object and an env object populated from JSON files in @shared/server/data/ (see Data models below).
Request and response handling
Route handlers use the standard web-platformRequest and Response APIs with no Node.js-specific extensions.
Reading request data:
Do not use Node.js-specific APIs (
fs, path, process.env, etc.) inside server routes. These APIs are not available in edge runtimes. Use the env parameter for data access instead.The worker model
In development and preview, Nue loads@shared/server/index.js inside a worker — a Bun-native environment that mimics edge runtime behavior. The worker:
- Imports your
index.jsand collects all registered routes. - Intercepts incoming requests before the static file handler.
- Matches requests by HTTP method and pathname.
- Calls your handler and returns the
Responsedirectly to the client.
null and Nue falls back to serving the corresponding static file from .dist/ (in preview) or from the source tree (in development).
Simulated Cloudflare headers
During development the worker automatically injects Cloudflare-style request headers so you can test geo-based logic without deploying:req.headers.get('cf-ipcountry') exactly as they would in production.
Hot reload in development
When the development server is running, changes to files inside@shared/server/ trigger a worker reload. The worker clears its route registry, re-imports index.js, and re-registers all routes — all without restarting the dev server.
Data models
JSON files placed in@shared/server/data/ are automatically loaded and passed to your route handlers as the env parameter. Each file becomes a model named after the file (without the .json extension):
id and created timestamp fields when loaded. The users model additionally provides login, logout, and authenticate helpers backed by session IDs stored in .nue/sessions.json.
Proxy mode
Proxy mode lets you test your frontend against a live remote backend instead of the local worker. Configure it with theserver.url and server.routes keys in site.yaml:
server.url is set, Nue skips the local worker entirely and forwards any request whose path starts with one of the listed prefixes to the remote URL. The proxy strips your local host and rewrites the destination:
Server routes and static pages together
Nue resolves each incoming request using the following priority order:- Server route match — if the worker (or proxy) claims the request, its
Responseis returned. - Static file — if no route matches, Nue looks for a file in
.dist/(preview) or the source tree (development). - 404 page — if
.dist/404.htmlexists, it is served for unmatched non-file requests.
blog/ section and a dynamic /api/ section in the same project with no configuration beyond registering routes in @shared/server/index.js.
Edge-compatible APIs
Write routes as if they will run in a Cloudflare Worker or Deno Deploy environment. The following globals are available in both development and production:| API | Notes |
|---|---|
Request | Standard Fetch API Request |
Response | Standard Fetch API Response, including Response.json() |
fetch | Standard global fetch |
URL | Standard URL |
crypto | Web Crypto API |
Headers | Standard Headers |
fs,path,os,child_processprocess.env(useenvparameter instead)- CommonJS
require() - Synchronous file I/O
Development vs. production behavior
Development (nue serve)
- Worker loaded from
@shared/server/index.js - Hot-reloaded on file changes
- Simulated Cloudflare headers injected
- Data models read from
@shared/server/data/*.json - Static files served from source tree
Preview (nue preview)
- Worker loaded from
@shared/server/index.js - No hot reload (restart to pick up changes)
- Same simulated headers as development
- Static files served from
.dist/ - Mirrors production behavior closely
@shared/server/index.js to your edge provider separately from the static .dist/ output. Point your CDN or edge worker at the same routes you registered locally.
When to use server routes vs. static generation
Use static generation (the default) when:- Content does not change per-request (blog posts, docs, marketing pages)
- No authentication or user state is required
- Maximum CDN cacheability is a priority
- You need to read or write to a database or external API
- Responses depend on the authenticated user or request headers
- You are handling form submissions, webhooks, or real-time data
/api/ routes are dynamic. This hybrid approach gives you the performance benefits of a static site alongside the flexibility of a backend where it matters.