Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/cav/deps.ts>http.listenAndServe

A server framework for Deno
Go to Latest
function http.listenAndServe
Deprecated
Deprecated

Use serve instead.

Constructs a server, creates a listener on the given address, accepts incoming connections, and handles requests on these connections with the given handler.

If the port is omitted from the ListenOptions, 80 is used.

If the host is omitted from the ListenOptions, the non-routable meta-address 0.0.0.0 is used.

import { listenAndServe } from "https://deno.land/std@0.224.0/http/server.ts";

const port = 4505;

console.log("server listening on http://localhost:4505");

await listenAndServe({ port }, (request) => {
const body = `Your user-agent is:\n\n${request.headers.get(
"user-agent",
) ?? "Unknown"}`;

return new Response(body, { status: 200 });
});
import { http } from "https://deno.land/x/cav@0.0.24/deps.ts";
const { listenAndServe } = http;

Parameters

config: Partial<Deno.ListenOptions>

The Deno.ListenOptions to specify the hostname and port.

handler: Handler

The handler for individual HTTP requests.

optional
options: ServeInit

Optional serve options.

Returns

Promise<void>