Platforms

Server.js is designed to run the same code unmodified across all supported runtimes and platforms. No adapter imports, no platform-specific entrypoints.

// This file works on Node.js, Bun, Cloudflare
// Workers, and Netlify Functions
import server from '@server/next';

export default server()
  .get('/', () => 'Hello world');

The same default export adapts to each runtime:

  • Node.js: run the file with node .; served over the built-in HTTP server.
  • Bun: run it with bun .; faster, and unlocks JSX and native S3 buckets.
  • Cloudflare Workers: the default export is a standard fetch handler.
  • Netlify Functions: exports a Netlify-compatible handler automatically.

Node.js

The default export default server() also starts an HTTP server and listens on the configured port (default 3000). Run with:

node index.js

Node.js 24+ is required.

Bun

Run with:

bun index.js

No extra setup needed. Bun also unlocks JSX templates and native S3 bucket support.

Cloudflare Workers

The default export is a standard fetch handler, which is what Cloudflare Workers expect. Deploy as usual with wrangler.

import server from '@server/next';

export default server()
  .get('/', () => 'Hello from the edge');

Netlify Functions

Server.js exports a callback method compatible with Netlify's function handler signature. The export default is set up automatically.

import server from '@server/next';

export default server()
  .get('/', () => 'Hello from Netlify');

Environment variables

Regardless of platform, these environment variables are read automatically if set:

VariableOptionDefault
PORTport3000
SECRETsecretrandom
PUBLICpublicnull
FAVICONfaviconnull
CORScorsnull
AUTHauthnull

See Options › Environment variables for the full list.