HTTP Server: Hello world
在 Github 上编辑
An example of a HTTP server that serves a "Hello World" message.
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);
使用 Deno CLI 在本地运行 此示例:
deno run --allow-net https://docs.denohub.com/examples/scripts/http_server.ts
在 Deno Deploy Playground 中尝试此示例: