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.
adapter-node
in most configurations.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
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;
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
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
For a complete example setup, check out my template repository: NextLegacy/SvelteKit-Deno-Tempalte
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.
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.
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 β
βββββββββββββ΄ββββββββββ΄ββββββββββ΄ββββββββββ΄ββββββββββ΄ββββββββββ΄ββββββββββ΄ββββββββββ
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.
You can find the source code on GitHub: https://github.com/nextlegacy/sveltekit-adapter-deno
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