Skip to main content

Quickstart

Get up and running with Deno in just a few minutes by building your first web server.
Make sure you have installed Deno before starting this tutorial.

Your first Deno program

Deno is most commonly used to build web servers. Let’s create a simple HTTP server that responds with “Hello, world!”.
1

Create a server file

Create a new file called server.ts with the following TypeScript code:
server.ts
Deno.serve((_req: Request) => {
  return new Response("Hello, world!");
});
This code creates an HTTP server using Deno’s built-in Deno.serve() function. The server responds to every request with “Hello, world!”.
2

Run the server

Run your server with the following command:
deno run --allow-net server.ts
The --allow-net flag grants permission to access the network. Deno is secure by default, so you must explicitly grant permissions.
3

Test your server

Open your browser and navigate to http://localhost:8000. You should see “Hello, world!” displayed.You can also test it from the command line:
curl http://localhost:8000

Understanding the code

Deno.serve()

The Deno.serve() function is Deno’s built-in HTTP server. It takes a handler function that receives a Request object and returns a Response:
Deno.serve((req: Request) => {
  return new Response("Hello, world!");
});

Permissions

Deno is secure by default. The --allow-net flag grants permission to access the network. Without this flag, the program would fail with a permission error. Learn more about Deno’s permission system.

Enhance your server

Add dynamic responses

server.ts
Deno.serve((req: Request) => {
  const url = new URL(req.url);
  
  if (url.pathname === "/") {
    return new Response("Welcome to Deno!");
  }
  
  if (url.pathname === "/about") {
    return new Response("This is a Deno server");
  }
  
  return new Response("Not found", { status: 404 });
});

Return JSON

server.ts
Deno.serve((req: Request) => {
  const data = {
    message: "Hello from Deno!",
    timestamp: new Date().toISOString(),
    path: new URL(req.url).pathname,
  };
  
  return Response.json(data);
});

Handle different HTTP methods

server.ts
Deno.serve(async (req: Request) => {
  const url = new URL(req.url);
  
  if (url.pathname === "/api/data" && req.method === "GET") {
    return Response.json({ items: ["apple", "banana", "orange"] });
  }
  
  if (url.pathname === "/api/data" && req.method === "POST") {
    const body = await req.json();
    return Response.json({ received: body }, { status: 201 });
  }
  
  return new Response("Not found", { status: 404 });
});

Running with TypeScript

Deno has native TypeScript support. You can use TypeScript features without any configuration:
server.ts
interface User {
  id: number;
  name: string;
  email: string;
}

const users: User[] = [
  { id: 1, name: "Alice", email: "[email protected]" },
  { id: 2, name: "Bob", email: "[email protected]" },
];

Deno.serve((req: Request) => {
  const url = new URL(req.url);
  
  if (url.pathname === "/users") {
    return Response.json(users);
  }
  
  const match = url.pathname.match(/^\/users\/(\d+)$/);
  if (match) {
    const userId = parseInt(match[1]);
    const user = users.find(u => u.id === userId);
    
    if (user) {
      return Response.json(user);
    }
    return new Response("User not found", { status: 404 });
  }
  
  return new Response("Not found", { status: 404 });
});

Development workflow

Watch mode

Use watch mode to automatically restart your server when files change:
deno run --allow-net --watch server.ts

Type checking

Deno type-checks your code by default. To explicitly check types without running:
deno check server.ts

REPL

Experiment with code interactively:
deno
> const response = await fetch("http://localhost:8000")
> await response.text()

Next steps

Now that you’ve built your first Deno application, explore more features:

Core commands

Learn essential Deno commands

Permissions

Understand Deno’s security model

Testing

Write tests for your application

Configuration

Configure your Deno project

Troubleshooting

If you see permission errors, make sure you’re using the appropriate --allow-* flags:
# Network access
deno run --allow-net server.ts

# File system read
deno run --allow-read server.ts

# Multiple permissions
deno run --allow-net --allow-read server.ts
If port 8000 is already in use, specify a different port:
Deno.serve({ port: 3000 }, (req) => {
  return new Response("Hello, world!");
});
Deno type-checks your code by default. If you encounter type errors, you can:
  1. Fix the type errors (recommended)
  2. Use // @ts-ignore to suppress specific errors
  3. Use --no-check flag to skip type checking (not recommended)

Build docs developers (and LLMs) love