npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nextrush/adapter-deno

v3.0.5

Published

Deno HTTP adapter for NextRush

Readme

@nextrush/adapter-deno

Deno HTTP adapter for NextRush. Connects your NextRush application to Deno's native Deno.serve() API.

Installation

import { createApp } from 'npm:@nextrush/core';
import { serve } from 'npm:@nextrush/adapter-deno';

Or use import maps in deno.json:

{
  "imports": {
    "@nextrush/core": "npm:@nextrush/core",
    "@nextrush/adapter-deno": "npm:@nextrush/adapter-deno",
    "@nextrush/router": "npm:@nextrush/router"
  }
}

Quick Start

import { createApp } from '@nextrush/core';
import { serve } from '@nextrush/adapter-deno';

const app = createApp();

app.use(async (ctx) => {
  ctx.json({ message: 'Hello from Deno!' });
});

serve(app, {
  port: 3000,
  onListen: ({ port }) => console.log(`🚀 Server running on port ${port}`),
});

Run

deno run --allow-net server.ts

API Reference

serve(app, options?)

Start an HTTP server for your application.

import { serve } from '@nextrush/adapter-deno';

const server = serve(app, {
  port: 3000,            // Default: 3000
  hostname: '0.0.0.0',   // Default: '0.0.0.0'
  shutdownTimeout: 30000,// Default: 30000 (ms)
  onListen: ({ port, hostname }) => { ... },
  onError: (error) => { ... },
  cert: certPem,         // Optional TLS certificate
  key: keyPem,           // Optional TLS key
});

// Server control
console.log(`Running on port ${server.port}`);
await server.close();

// Wait for server to finish
await server.finished;

createHandler(app)

Create a handler for custom Deno.serve configurations.

import { createHandler } from '@nextrush/adapter-deno';

const handler = createHandler(app);

// Use with custom Deno.serve setup
Deno.serve({
  port: 3000,
  handler,
  // ... additional Deno options
});

listen(app, port?)

Quick start shorthand with console output.

import { listen } from '@nextrush/adapter-deno';

listen(app, 3000);
// Output: 🚀 NextRush listening on http://localhost:3000 (Deno)

Context

The DenoContext provides the standard NextRush Context interface:

app.use(async (ctx) => {
  // Request (input)
  ctx.method; // 'GET', 'POST', etc.
  ctx.path; // '/users/123'
  ctx.query; // { page: '1' }
  ctx.params; // { id: '123' } (from router)
  ctx.headers; // Request headers
  ctx.body; // Parsed body (from body-parser)
  ctx.ip; // Client IP

  // Runtime info
  ctx.runtime; // 'deno'
  ctx.bodySource; // BodySource for raw body access

  // Response (output)
  ctx.status = 201;
  ctx.json({ data: '...' });
  ctx.send('text');
  ctx.html('<h1>Hello</h1>');
  ctx.redirect('/other');

  // Headers
  ctx.set('X-Custom', 'value');
  ctx.get('content-type');

  // Middleware
  await ctx.next();

  // Raw access (escape hatch)
  ctx.raw.req; // Web API Request object (Deno)
});

HTTPS / TLS

const cert = await Deno.readTextFile('./cert.pem');
const key = await Deno.readTextFile('./key.pem');

serve(app, {
  port: 443,
  cert,
  key,
});

Deno Permissions

NextRush requires minimal permissions:

# Basic server
deno run --allow-net server.ts

# With file serving
deno run --allow-net --allow-read server.ts

# With environment variables
deno run --allow-net --allow-env server.ts

Error Handling

serve(app, {
  onError: (error) => {
    console.error('Server error:', error);
    // Log to monitoring service
  },
});

// In middleware
app.use(async (ctx) => {
  ctx.throw(404, 'Not found');
  // or
  ctx.assert(user, 404, 'User not found');
});

Full Example

// server.ts
import { createApp } from '@nextrush/core';
import { createRouter } from '@nextrush/router';
import { json } from '@nextrush/body-parser';
import { cors } from '@nextrush/cors';
import { serve } from '@nextrush/adapter-deno';

const app = createApp();
const router = createRouter();

// Middleware
app.use(cors());
app.use(json());

// Routes
router.get('/health', (ctx) => {
  ctx.json({
    status: 'healthy',
    runtime: ctx.runtime, // 'deno'
    version: Deno.version.deno,
  });
});

router.post('/users', async (ctx) => {
  const { name, email } = ctx.body as { name: string; email: string };

  ctx.status = 201;
  ctx.json({ id: Date.now(), name, email });
});

router.get('/users/:id', (ctx) => {
  const { id } = ctx.params;
  ctx.json({ id, name: 'John Doe' });
});

// Mount router — Hono-style
app.route('/', router);

// Start server
serve(app, {
  port: 3000,
  onListen: ({ port }) => {
    console.log(`🚀 Server running on http://localhost:${port}`);
    console.log(`   Runtime: Deno ${Deno.version.deno}`);
  },
});

DX Consistency

All NextRush adapters share the same interface. Change the import to switch runtimes:

// Deno
import { serve } from '@nextrush/adapter-deno';

// Node.js
import { serve } from '@nextrush/adapter-node';

// Bun
import { serve } from '@nextrush/adapter-bun';

serve(app, { port: 3000 });

Deno Deploy

Use createHandler for Deno Deploy:

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

Types

import type { ServeOptions, ServerInstance } from '@nextrush/adapter-deno';

import { DenoContext } from '@nextrush/adapter-deno';

Requirements

  • Deno >= 2.0
  • NextRush >= 3.0.0

See Also

License

MIT