Adapter for SvelteKit apps that generates a standalone Node server
npx @tessl/cli install tessl/npm-sveltejs--adapter-node@5.3.0@sveltejs/adapter-node is a SvelteKit adapter that generates a standalone Node.js server for SvelteKit applications. It transforms SvelteKit apps into production-ready Node server builds with support for server-side rendering, API routes, static asset serving, and comprehensive environment configuration.
npm install @sveltejs/adapter-nodeimport adapter from '@sveltejs/adapter-node';For CommonJS:
const adapter = require('@sveltejs/adapter-node');// svelte.config.js
import adapter from '@sveltejs/adapter-node';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter()
}
};
export default config;With configuration options:
// svelte.config.js
import adapter from '@sveltejs/adapter-node';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter({
out: 'build',
precompress: true,
envPrefix: 'MY_CUSTOM_'
})
}
};
export default config;The adapter works by:
The generated server includes:
Creates and configures the SvelteKit adapter with optional settings.
/**
* Creates a SvelteKit adapter for Node.js deployment
* @param options - Configuration options for the adapter
* @returns Configured SvelteKit adapter
*/
export default function adapter(options?: AdapterOptions): Adapter;
interface AdapterOptions {
/** Output directory for the generated server (default: 'build') */
out?: string;
/** Enable gzip/brotli compression of static assets (default: true) */
precompress?: boolean;
/** Prefix for environment variables (default: '') */
envPrefix?: string;
}
interface Adapter {
name: string;
adapt(builder: Builder): Promise<void>;
supports: {
read(): boolean;
instrumentation(): boolean;
};
}
interface Builder {
log: { minor(message: string): void };
rimraf(path: string): void;
mkdirp(path: string): void;
config: { kit: { paths: { base: string } } };
prerendered: { paths: string[] };
getBuildDirectory(name: string): string;
writeClient(dest: string): void;
writePrerendered(dest: string): void;
writeServer(dest: string): void;
generateManifest(options: { relativePath: string }): string;
compress(path: string): Promise<void>;
copy(from: string, to: string, options?: { replace?: Record<string, string> }): void;
hasServerInstrumentationFile?(): boolean;
instrument?(options: { entrypoint: string; instrumentation: string; module: { exports: string[] } }): void;
}The generated server supports extensive environment variable configuration:
// Server binding configuration
SOCKET_PATH?: string; // Unix socket path (alternative to HOST/PORT)
HOST?: string; // Server host (default: '0.0.0.0')
PORT?: string; // Server port (default: '3000')
// Server lifecycle
SHUTDOWN_TIMEOUT?: string; // Graceful shutdown timeout in seconds (default: '30')
IDLE_TIMEOUT?: string; // Idle timeout for socket activation (default: '0')
// Socket activation (systemd)
LISTEN_PID?: string; // Process ID for socket activation
LISTEN_FDS?: string; // Number of file descriptors for socket activation// Origin and URL configuration
ORIGIN?: string; // Override automatic origin detection
BODY_SIZE_LIMIT?: string; // Request body size limit (default: '512K')
// Reverse proxy headers
XFF_DEPTH?: string; // X-Forwarded-For header depth (default: '1')
ADDRESS_HEADER?: string; // Custom client address header name
PROTOCOL_HEADER?: string; // Custom protocol header name
HOST_HEADER?: string; // Custom host header name
PORT_HEADER?: string; // Custom port header nameAll environment variables (except LISTEN_PID and LISTEN_FDS) can be prefixed using the envPrefix option.
Global platform interface extension for accessing Node.js request object.
declare global {
namespace App {
interface Platform {
/** The original Node.js HTTP request object */
req: import('node:http').IncomingMessage;
}
}
}After building with the adapter, the generated server can be started with:
node build/index.jsThe server will log its binding information and accept requests on the configured host and port.
# Basic configuration
HOST=127.0.0.1 PORT=8080 node build/index.js
# With custom prefix
MY_APP_HOST=127.0.0.1 MY_APP_PORT=8080 node build/index.js
# With reverse proxy headers
ADDRESS_HEADER=x-real-ip PROTOCOL_HEADER=x-forwarded-proto node build/index.js
# With body size limit
BODY_SIZE_LIMIT=1M node build/index.js
# Unix socket
SOCKET_PATH=/tmp/app.sock node build/index.jsThe generated server supports graceful shutdown via SIGTERM and SIGINT signals, with configurable timeout:
# Custom shutdown timeout (60 seconds)
SHUTDOWN_TIMEOUT=60 node build/index.jsFor systemd socket activation:
# Systemd will set these automatically
LISTEN_PID=1234 LISTEN_FDS=1 node build/index.js