Complete the code to import a module in Deno.
import { [1] } from "https://deno.land/std@0.177.0/fs/mod.ts";
The readDir function is imported from Deno's standard library to read directory contents.
Complete the code to start a simple HTTP server in Deno.
import { serve } from "https://deno.land/std@0.177.0/http/server.ts"; serve(() => new Response("Hello, Deno!"), { port: [1] });
Port 8080 is commonly used for development servers and is a good choice here.
Fix the error in the code to correctly read environment variables in Deno.
const dbPassword = Deno.[1].get("DB_PASSWORD");
Deno provides environment variables through Deno.env. The get method retrieves the variable value.
Fill both blanks to create a secure file read function that handles errors in Deno.
async function readConfig(path) {
try {
const data = await Deno.[1](path, { [2]: "utf8" });
return data;
} catch {
return null;
}
}readFile which returns bytes, not text.readTextFile reads a file as text, and encoding specifies the text encoding.
Fill all three blanks to create a Deno server that logs requests and responds with JSON.
import { serve } from "https://deno.land/std@0.177.0/http/server.ts"; serve(async (req) => { console.[1]("Request received"); const data = { message: "Hello from Deno" }; return new Response(JSON.[2](data), { headers: { "Content-Type": [3] } }); });
console.error instead of console.log.console.log prints messages, JSON.stringify converts objects to JSON strings, and the content type must be "application/json".
