Deno logoDenoby example

Intermediate

clideploy

HTTP Server: Hello World

An example of a HTTP server that serves a "Hello World" message.

Import the http server from std/http.
import { serve } from "https://deno.land/std@0.175.0/http/server.ts";
HTTP servers need a handler function. This function is called for every request that comes in. It must return a `Response`. The handler function can be asynchronous (it may return a `Promise`).
function handler(_req: Request): Response {
  return new Response("Hello, World!");
}
To start the server on the default port, call `serve` with the handler.
console.log("Listening on http://localhost:8000");
serve(handler);

Run this example locally using the Deno CLI:

deno run --allow-net https://byexample-wwv03xf36j0g.deno.dev/http-server.ts

Try this example in a Deno Deploy playground:

Additional resources: