Deno LandDeno

Deploy Docs

Hello World

As a first introduction to Deno Deploy, lets deploy a little hello world script. This will just respond to all incoming HTTP requests with Hello World and a 200 OK HTTP status. We will be deploying this script from a URL.

Lets start by writing the script to deploy. Deno Deploy lets you listen for incoming HTTP requests using the same Fetch Event API used in Service Workers. This API works by registering a listener using the global addEventListener, with the event type fetch. The second parameter provided to addEventListener is a callback that is called with a FetchEvent property for every request.

addEventListener("fetch", (event) => {/* handle the FetchEvent here */});

The FetchEvent object contains two main fields that are of interest to us: request and respondWith. The request can be used to retrieve information about the incoming request, like the HTTP method, URL, headers, or request body. It is of type Request (from the Fetch API). The second field (respondWith), is a method that you can call with either a Response or Promise<Response>. This is the response to the incoming request.

Lets use this information to finish our hello world script:

addEventListener("fetch", (event) => {
  const response = new Response("Hello World!", {
    headers: { "content-type": "text/plain" },
  });
  event.respondWith(response);
});

You can find this script hosted at https://deno.com/examples/hello.js.

Now, we will deploy this script to Deno Deploy. To start, navigate to https://dash.deno.com, and sign in. Then click on New Project button. Input any project name in the input box and click on Create button. Then press the Deploy from URL button at the top. You can now enter the URL of the hello world script (https://deno.com/examples/hello.js). Then press the Deploy button.

You should now be navigated to the Project Overview page. From this page you can review your project's settings, add/remove domains, or view the deployment logs. For now, just navigate to the domain you deployed to, and view your script in action.

Congratulations. You have now deployed your first script to Deno Deploy 👏!


Deploy this example


Please file an issue in our feedback repository if you find any problem in Deploy service or documentation.