# Deno HTTP Server

> Secure JavaScript/TypeScript runtime with native HTTP server.

- Category: Web Servers & Reverse Proxies
- Difficulty: beginner
- Components: deno
- Tags: deno, typescript, secure, runtime, rust
- Source: https://docker.recipes/web-servers/deno-server

## Overview

Deno is a modern JavaScript and TypeScript runtime built on Rust and the V8 JavaScript engine, created by Ryan Dahl (the original creator of Node.js) to address security and design issues in Node.js. Unlike Node.js, Deno is secure by default, requiring explicit permissions for file system access, network operations, and environment variables. It provides native TypeScript support without configuration, built-in tooling including formatters and linters, and uses URL-based module imports that eliminate the need for a package.json or node_modules directory.

This Docker configuration creates a containerized Deno HTTP server that runs with minimal permissions, mounting your application code as read-only for enhanced security. The setup leverages Deno's built-in HTTP server capabilities through the Deno.serve() API, providing a lightweight web server that can handle modern JavaScript and TypeScript applications without additional dependencies or build steps.

This stack is ideal for developers building modern web APIs, TypeScript enthusiasts wanting zero-configuration development environments, and security-conscious teams requiring explicit permission controls. The combination offers rapid prototyping capabilities with production-ready security features, making it perfect for serverless-style applications, REST APIs, and microservices that benefit from Deno's batteries-included approach and modern web standards compliance.

## Features

- Secure by default with explicit permission model requiring --allow-net and --allow-read flags
- Native TypeScript support without transpilation configuration or build steps
- Built-in HTTP server using Deno.serve() API with modern Request/Response objects
- URL-based module imports eliminating package.json and node_modules complexity
- Integrated development tools including formatter (deno fmt), linter (deno lint), and test runner
- Web-standard APIs following modern browser specifications for consistent behavior
- Single executable runtime with no external dependencies required
- Read-only volume mounting for enhanced container security and immutable deployments

## Use cases

- REST API backends for single-page applications requiring TypeScript without build complexity
- Serverless function development and testing with security-first permission controls
- Educational TypeScript projects where students can focus on code rather than tooling setup
- Microservices architecture where each service needs minimal attack surface and explicit permissions
- Rapid prototyping of web APIs with modern JavaScript features and zero configuration
- Edge computing applications requiring lightweight runtime with built-in HTTP capabilities
- Development teams migrating from Node.js seeking improved security and TypeScript experience

## Prerequisites

- Docker and Docker Compose installed on the host system
- Basic understanding of JavaScript/TypeScript and HTTP server concepts
- Minimum 128MB RAM allocated to Docker container (512MB recommended for production)
- Port 8000 available on the host system for HTTP server binding
- Application code directory structure with server.ts entry point file
- Familiarity with Deno's permission system and command-line flags

## docker-compose.yml

```yaml
services:
  deno:
    image: denoland/deno:latest
    container_name: deno-server
    restart: unless-stopped
    command: run --allow-net --allow-read /app/server.ts
    volumes:
      - ./app:/app:ro
    ports:
      - "8000:8000"
    networks:
      - deno-network

networks:
  deno-network:
    driver: bridge
```

## .env

```bash
# Deno server configuration
```

## Usage notes

- Docs: https://docs.deno.com/
- Secure by default - explicit permissions required (--allow-net, --allow-read)
- Native TypeScript support - no config needed
- Built-in formatter, linter, test runner, bundler
- Deno.serve() for HTTP: Deno.serve((req) => new Response('Hi'))
- Standard library at https://deno.land/std - batteries included

## Troubleshooting

- PermissionDenied errors: Add required permission flags like --allow-net, --allow-read, or --allow-env to the command
- Module not found from URL imports: Ensure internet connectivity in container and verify module URLs are accessible
- Container exits immediately: Check that server.ts exists in ./app directory and contains proper Deno.serve() implementation
- Port binding fails: Verify port 8000 is not in use by another service and matches the port in your Deno server code
- TypeScript compilation errors: Deno's strict TypeScript checking may require proper type annotations unlike Node.js environments
- Performance issues: Increase container memory allocation above 128MB minimum for production workloads

