@nextrush/adapter-deno
Deno HTTP adapter for NextRush — connects your application to Deno.serve().
Connect your NextRush application to Deno's native Deno.serve() API. This adapter bridges NextRush's middleware system to Deno's HTTP server.
Installation
Import directly in Deno (no npm required):
import { createApp } from 'npm:@nextrush/core';
import { serve } from 'npm:@nextrush/adapter-deno';Or with import maps in deno.json:
{
"imports": {
"@nextrush/core": "npm:@nextrush/core",
"@nextrush/adapter-deno": "npm:@nextrush/adapter-deno"
}
}Deno Permissions Required
Deno requires explicit network permission to run an HTTP server. Use --allow-net at minimum. See
Deno Permissions for details.
Quick Start
import { createApp } from '@nextrush/core';
import { listen } from '@nextrush/adapter-deno';
const app = createApp();
app.use(async (ctx) => {
ctx.json({ runtime: 'deno', message: 'Hello World!' });
});
listen(app, 3000);
// Output: 🚀 NextRush listening on http://localhost:3000 (Deno)Run with Deno:
deno run --allow-net src/main.tsAPI Reference
serve(app, options?)
Start the HTTP server with full configuration control.
import { createApp } from '@nextrush/core';
import { serve } from '@nextrush/adapter-deno';
const app = createApp();
const server = serve(app, {
port: 3000,
hostname: '0.0.0.0',
onListen: ({ port, hostname }) => {
console.log(`Server running at http://${hostname}:${port}`);
},
onError: (error) => {
console.error('Server error:', error);
},
});ServeOptions
ServeOptions
| Property | Type | Description |
|---|---|---|
port | number= 3000 | Port to listen on |
hostname | string= '0.0.0.0' | Hostname to bind to |
onListen? | (info: { port: number; hostname: string }) => void | Callback when server starts listening |
onError? | (error: Error) => void | Custom error handler for uncaught server errors |
cert? | string | TLS certificate in PEM format |
key? | string | TLS private key in PEM format |
shutdownTimeout | number= 30000 | Grace period in ms for draining in-flight requests during shutdown |
ServerInstance
The returned server instance provides control methods:
interface ServerInstance {
server: DenoServer; // Underlying Deno server
port: number; // Actual port
hostname: string; // Actual hostname
close(): Promise<void>; // Graceful shutdown
address(): { port; hostname };
finished: Promise<void>; // Resolves when server stops
}listen(app, port?)
Quick-start shorthand with default logging.
import { createApp } from '@nextrush/core';
import { listen } from '@nextrush/adapter-deno';
const app = createApp();
const server = listen(app, 3000);
// Output: 🚀 NextRush listening on http://localhost:3000 (Deno)createHandler(app)
Create a raw handler for advanced use cases.
import { createApp } from '@nextrush/core';
import { createHandler } from '@nextrush/adapter-deno';
const app = createApp();
const handler = createHandler(app);
// Use directly with Deno.serve
Deno.serve({ handler, port: 3000 });TLS/HTTPS
Enable HTTPS with TLS certificates:
import { serve } from '@nextrush/adapter-deno';
const server = serve(app, {
port: 443,
cert: await Deno.readTextFile('./cert.pem'),
key: await Deno.readTextFile('./key.pem'),
});Deno Permissions
NextRush requires network permission to run:
# Minimum required
deno run --allow-net app.ts
# With file access (for static files, etc.)
deno run --allow-net --allow-read app.ts
# Development (more permissive)
deno run --allow-all app.tsServer Lifecycle
Waiting for Server Finish
Deno adapter exposes a finished promise:
const server = serve(app, { port: 3000 });
// Wait for server to complete (useful in scripts)
await server.finished;Graceful Shutdown
Handle server shutdown properly:
const server = serve(app, { port: 3000 });
Deno.addSignalListener('SIGTERM', async () => {
console.log('Shutting down...');
await server.close(); // Closes app + server
Deno.exit(0);
});Client IP Access
The adapter extracts client IP from Deno's connection info:
app.use(async (ctx) => {
// Available via context
const ip = ctx.ip; // From remoteAddr
ctx.json({ clientIp: ip });
});Deno Deploy
For Deno Deploy, use createHandler:
import { createApp } from '@nextrush/core';
import { createHandler } from '@nextrush/adapter-deno';
const app = createApp();
app.use(async (ctx) => {
ctx.json({
message: 'Hello from Deno Deploy!',
region: Deno.env.get('DENO_REGION'),
});
});
Deno.serve(createHandler(app));TypeScript
Full TypeScript support with Deno's native TS:
import type { Application } from '@nextrush/core';
import type { ServeOptions, ServerInstance } from '@nextrush/adapter-deno';
import { serve, listen, createHandler } from '@nextrush/adapter-deno';
const options: ServeOptions = {
port: 3000,
hostname: '0.0.0.0',
};
const server: ServerInstance = serve(app, options);Related
- Adapters Overview — Understanding runtime adapters
- @nextrush/adapter-node — Node.js adapter
- @nextrush/adapter-bun — Bun adapter
- @nextrush/adapter-edge — Edge runtime adapter