sveltekit-adapter-deno Svelte Themes

Sveltekit Adapter Deno

drop-in replacement for `@sveltejs/adapter-node`, utilizing Deno's built-in `Deno.serve`

SvelteKit Adapter for Deno πŸ¦•

Adapter for SvelteKit apps that generates a standalone Deno server. πŸ¦•

This adapter aims to be a drop-in replacement for @sveltejs/adapter-node, utilizing Deno's built-in Deno.serve for handling HTTP requests and serving static files, removing the need for Node.js ecosystem dependencies like Polka or Sirv. ✨

For more information on SvelteKit adapters in general, see the official documentation.

Key Features πŸ”₯

  • πŸ¦• Deno Runtime: Uses Deno's built-in features for handling HTTP requests and serving static files.
  • πŸ“¦ Basically no runtime Dependencies: Finished build only uses Deno's standard library and Node.js compatible imports.
  • πŸ”„ Drop-in Replacement: Designed to work seamlessly as a replacement for adapter-node in most configurations.

Installation πŸ› οΈ

Install the adapter as a development dependency in your SvelteKit project:

# Using deno
deno install npm:@nextlegacy/sveltekit-adapter-deno

# Using npm
npm install -D @nextlegacy/sveltekit-adapter-deno

# Using yarn
yarn add -D @nextlegacy/sveltekit-adapter-deno

# Using pnpm
pnpm add -D @nextlegacy/sveltekit-adapter-deno

Usage πŸš€

  1. Configure svelte.config.js: Update your configuration to use the adapter:

    import adapter from "@nextlegacy/sveltekit-adapter-deno";
    
    /** @type {import("@sveltejs/kit").Config} */
    const config = {
      kit: {
        adapter: adapter({
          // Optional: specify adapter options here (see Configuration below)
        }),
    
        // other kit options...
      }
    };
    
    export default config;
    
  2. Build your application: Use the Deno task defined in your deno.json (or the corresponding npm script):

    # Using Deno tasks (recommended)
    deno task build
    
    # Or using npm scripts (if configured)
    # npm run build
    
  3. Run the Deno server: Execute the generated entry point build/index.ts with Deno, granting necessary permissions:

    deno run --allow-net --allow-read --allow-env build/index.ts
    

Example Project 🌟

For a complete example setup, check out my template repository: NextLegacy/SvelteKit-Deno-Tempalte

Configuration βš™οΈ

This adapter accepts the same options object as the official @sveltejs/adapter-node:

Option Type Default Description
out string 'build' The directory to write the server files to.
precompress boolean true If true, precompresses static assets using gzip and brotli.
envPrefix string '' Specifies a prefix for environment variables passed to the server. See SvelteKit docs.

Refer to the adapter-node documentation for details on all available options.

Environment Variables πŸ“‘

This adapter recognizes a subset of the environment variables used by @sveltejs/adapter-node to control the built server's behavior.

Note: Variables related to client address headers (ADDRESS_HEADER, XFF_DEPTH), origin determination (ORIGIN, PROTOCOL_HEADER, HOST_HEADER, PORT_HEADER), and systemd socket activation (LISTEN_PID, LISTEN_FDS) are not currently implemented in this adapter.

The following variables are supported:

Variable Default Description
HOST '0.0.0.0' The IP address to bind to.
PORT 3000 (if SOCKET_PATH unset) The port to listen on.
SOCKET_PATH false Unix socket path to listen on (overrides HOST/PORT).
BODY_SIZE_LIMIT 512K Maximum request body size (e.g., 512K, 1M, Infinity).
SHUTDOWN_TIMEOUT 30 Seconds to wait for graceful shutdown.
IDLE_TIMEOUT 0 Seconds of inactivity before server exits (useful for socket activation).

For a detailed explanation of each variable and its usage, please refer to the @sveltejs/adapter-node Environment Variables Documentation.

Benchmarks πŸ“Š

I plan to add better real-world benchmarks soon. For now, here's a simple proof of concept benchmark using autocannon and a relatively simple SvelteKit project that I had lying around:

(Note: Benchmarks run using autocannon -c 100 -d 5 -p 10. Your results may vary based on hardware and application complexity.) (run locally w/ Deno 2.3.1)

@nextlegacy/adapter-deno:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Stat    β”‚ 2.5%   β”‚ 50%    β”‚ 97.5%  β”‚ 99%    β”‚ Avg       β”‚ Stdev    β”‚ Max    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Latency β”‚ 147 ms β”‚ 222 ms β”‚ 239 ms β”‚ 240 ms β”‚ 219.4 ms  β”‚ 23.84 ms β”‚ 250 ms β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Stat      β”‚ 1%      β”‚ 2.5%    β”‚ 50%     β”‚ 97.5%   β”‚ Avg     β”‚ Stdev   β”‚ Min     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Req/Sec   β”‚ 4,203   β”‚ 4,203   β”‚ 4,523   β”‚ 4,535   β”‚ 4,453.2 β”‚ 126.89  β”‚ 4,201   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Bytes/Sec β”‚ 70.8 MB β”‚ 70.8 MB β”‚ 76.2 MB β”‚ 76.4 MB β”‚ 75 MB   β”‚ 2.15 MB β”‚ 70.8 MB β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

@sveltejs/adapter-node:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Stat    β”‚ 2.5%   β”‚ 50%    β”‚ 97.5%  β”‚ 99%    β”‚ Avg       β”‚ Stdev   β”‚ Max    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Latency β”‚ 250 ms β”‚ 336 ms β”‚ 448 ms β”‚ 481 ms β”‚ 345.96 ms β”‚ 48.07 msβ”‚ 535 ms β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Stat      β”‚ 1%      β”‚ 2.5%    β”‚ 50%     β”‚ 97.5%   β”‚ Avg     β”‚ Stdev   β”‚ Min     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Req/Sec   β”‚ 2,197   β”‚ 2,197   β”‚ 2,967   β”‚ 3,131   β”‚ 2,807   β”‚ 336.18  β”‚ 2,197   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Bytes/Sec β”‚ 37 MB   β”‚ 37 MB   β”‚ 50 MB   β”‚ 52.8 MB β”‚ 47.3 MB β”‚ 5.66 MB β”‚ 37 MB   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Production Readiness βœ…

I am slowly starting to use this adapter in production environments as a drop-in replacement for adapter-node without issues so far.

However, as a community project leveraging newer Deno APIs, I recommend performing thorough testing for your specific use case before deploying to critical production systems. πŸ§ͺ While it aims for stability and follows @sveltejs/adapter-node's behavior closely, 100% production readiness compared to the more battle-tested @sveltejs/adapter-node cannot be guaranteed at this stage.

Repository πŸ’Ύ

You can find the source code on GitHub: https://github.com/nextlegacy/sveltekit-adapter-deno

Contributing & Support β™₯️

Contributions are welcome! Please feel free to open an issue or submit a pull request.

You can also contact me on various platforms: ✨nextlegacy.de/contact

License πŸ“œ

MIT

Top categories

Loading Svelte Themes