CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-sveltejs--adapter-node

Adapter for SvelteKit apps that generates a standalone Node server

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

@sveltejs/adapter-node

@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.

Package Information

  • Package Name: @sveltejs/adapter-node
  • Package Type: npm
  • Language: JavaScript/TypeScript
  • Installation: npm install @sveltejs/adapter-node

Core Imports

import adapter from '@sveltejs/adapter-node';

For CommonJS:

const adapter = require('@sveltejs/adapter-node');

Basic Usage

// 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;

Architecture

The adapter works by:

  1. Build Process: Transforms SvelteKit app into standalone Node.js server
  2. Asset Handling: Generates optimized client assets with optional compression
  3. Server Generation: Creates Node.js server with request handler and lifecycle management
  4. Environment Configuration: Supports extensive environment variable customization
  5. Production Deployment: Outputs production-ready server that can run independently

The generated server includes:

  • Static asset serving with caching headers
  • Server-side rendering (SSR) with SvelteKit integration
  • Prerendered route handling
  • Graceful shutdown and socket activation support
  • Configurable security headers and reverse proxy support

Capabilities

Adapter Factory Function

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;
}

Generated Server Environment Variables

The generated server supports extensive environment variable configuration:

Core Server 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

Request Handling Configuration

// 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 name

All environment variables (except LISTEN_PID and LISTEN_FDS) can be prefixed using the envPrefix option.

Type Definitions

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;
    }
  }
}

Deployment

After building with the adapter, the generated server can be started with:

node build/index.js

The server will log its binding information and accept requests on the configured host and port.

Environment Variable Examples

# 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.js

Graceful Shutdown

The generated server supports graceful shutdown via SIGTERM and SIGINT signals, with configurable timeout:

# Custom shutdown timeout (60 seconds)
SHUTDOWN_TIMEOUT=60 node build/index.js

Socket Activation

For systemd socket activation:

# Systemd will set these automatically
LISTEN_PID=1234 LISTEN_FDS=1 node build/index.js

docs

index.md

tile.json