📖 Scenario: You want to share a simple web page with your friends using Deno Deploy, a platform that lets you run Deno code on the internet easily.This project will guide you step-by-step to create a basic web server and deploy it to Deno Deploy.
🎯 Goal: Build a simple Deno web server that responds with a friendly message and prepare it for deployment on Deno Deploy.
📋 What You'll Learn
Create a basic HTTP server using Deno's standard library
Set a port number configuration variable
Write the core logic to handle HTTP requests and respond with a message
Add the final export statement for Deno Deploy compatibility
💡 Why This Matters
🌍 Real World
Deploying small web services or APIs quickly without managing servers.
💼 Career
Understanding Deno Deploy is useful for modern backend development and serverless deployment roles.
Progress0 / 4 steps
1
Set up the HTTP server import
Write an import statement to bring in the serve function from https://deno.land/std@0.203.0/http/server.ts.
Deno
Hint
Use import { serve } from the Deno standard library URL for HTTP server.
2
Define the port number
Create a constant variable called PORT and set it to Number(Deno.env.get("PORT") ?? "8000").
Deno
Hint
Use const PORT = Number(Deno.env.get("PORT") ?? "8000"); to set the port number from the environment variable or default to 8000.
3
Create the request handler
Write an async function called handler that takes a Request object and returns a new Response with the text "Hello from Deno Deploy!".
Deno
Hint
Define async function handler(request: Request) and return new Response("Hello from Deno Deploy!", { status: 200 }).
4
Start the server with export
Call serve with the handler function and port set to PORT. Export this call as the default export.
Deno
Hint
Use export default serve(handler, { port: PORT }) to start the server for Deno Deploy.
Practice
(1/5)
1. What is the main purpose of deno deploy in Deno?
easy
A. To run Deno scripts locally without internet
B. To install Deno on your computer
C. To create a new Deno project template
D. To publish your Deno app online as a serverless function
Solution
Step 1: Understand the command purpose
deno deploy is used to publish apps online, not for local installs or running scripts.
Step 2: Match the description to the command
Publishing as serverless functions matches the description of deno deploy.
Final Answer:
To publish your Deno app online as a serverless function -> Option D
Quick Check:
deno deploy = publish app online [OK]
Hint: Remember: deploy means publish online [OK]
Common Mistakes:
Confusing deploy with install
Thinking deploy runs code locally
Assuming deploy creates projects
2. Which of the following is the correct command to deploy a Deno project located in the current folder?
easy
A. deno deploy --install
B. deno deploy .
C. deno run deploy
D. deno start deploy
Solution
Step 1: Identify the correct deploy syntax
The command deno deploy . tells Deno to deploy the current folder project.
Step 2: Check other options for correctness
Options B, C, and D are invalid commands for deployment.
Final Answer:
deno deploy . -> Option B
Quick Check:
Deploy current folder = deno deploy . [OK]
Hint: Use dot (.) to deploy current folder [OK]
Common Mistakes:
Using deno run instead of deno deploy
Adding wrong flags like --install
Using deno start which is not a Deno command
3. Given this command run in your terminal: deno deploy https://github.com/user/myapp, what will happen?
medium
A. Deno will deploy the app from the GitHub repo URL as a serverless app
B. Deno will clone the repo locally but not deploy
C. Deno will throw a syntax error because URLs are not allowed
D. Deno will run the app locally without deploying
Solution
Step 1: Understand deploying from a repo URL
Deno Deploy supports deploying directly from GitHub repo URLs.
Step 2: Analyze the command behavior
The command deploys the app serverlessly from the given URL, no local clone or syntax error occurs.
Final Answer:
Deno will deploy the app from the GitHub repo URL as a serverless app -> Option A
Quick Check:
Deploy from URL = deploy serverless app [OK]
Hint: Deploy accepts GitHub URLs directly [OK]
Common Mistakes:
Thinking deploy clones repo locally
Assuming URLs cause syntax errors
Confusing deploy with local run
4. You run deno deploy myapp but get an error saying "No such file or directory". What is the most likely cause?
medium
A. You forgot to install Deno before deploying
B. The internet connection is down
C. The folder or file named 'myapp' does not exist in the current directory
D. You need to run deno run myapp first
Solution
Step 1: Interpret the error message
"No such file or directory" means the path 'myapp' is missing locally.
Step 2: Match error to cause
Since deploy expects a valid path or URL, missing folder causes this error.
Final Answer:
The folder or file named 'myapp' does not exist in the current directory -> Option C
Quick Check:
Missing folder = No such file error [OK]
Hint: Check folder exists before deploying [OK]
Common Mistakes:
Assuming Deno is not installed
Blaming internet connection for local file errors
Confusing deploy with run command
5. You want to deploy a Deno app that uses environment variables securely on Deno Deploy. Which approach is best?
hard
A. Set environment variables in Deno Deploy dashboard and access them via Deno.env.get()
B. Hardcode environment variables in your source code before deploying
C. Pass environment variables as command line arguments to deno deploy
D. Store environment variables in a local .env file and deploy it with your app
Solution
Step 1: Understand environment variable best practices
Hardcoding or deploying .env files risks exposing secrets publicly.