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

std/http/server.ts>listenAndServe

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function listenAndServe
import { listenAndServe } from "https://deno.land/std@0.61.0/http/server.ts";

Start an HTTP server with given options and request handler

const body = "Hello World\n";
const options = { port: 8000 };
listenAndServe(options, (req) => {
  req.respond({ body });
});

Parameters

addr: string | HTTPOptions

Server configuration

handler: (req: ServerRequest) => void

Request handler

Returns

Promise<void>