Skip to main content

HTTP Server: Hello world

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

Edit on Github
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 `Deno.serve` with the handler.
Deno.serve(handler);

Run this example locally using the Deno CLI:

deno run --allow-net https://docs.deno.com/examples/http-server.ts

Try this example in a Deno Deploy playground:

Deploy

Additional resources