std/http/mod.ts

Deno standard library
Go to Latest
function listenAndServe
import { listenAndServe } from "https://deno.land/std@0.81.0/http/mod.ts?s=listenAndServe";

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[src]

Server configuration

handler: (req: ServerRequest) => void[src]

Request handler

Returns

Promise<void>[src]