Bird
Raised Fist0
Denoframework~10 mins

Why production Deno needs careful architecture - Test Your Understanding

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import a module in Deno.

Deno
import { [1] } from "https://deno.land/std@0.177.0/fs/mod.ts";
Drag options to blanks, or click blank then click option'
AreadTextFile
BreadFileStr
CreadDir
DreadFileSync
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a function that reads file contents instead of directory listing.
Using a function not available in the imported module.
2fill in blank
medium

Complete the code to start a simple HTTP server in Deno.

Deno
import { serve } from "https://deno.land/std@0.177.0/http/server.ts";

serve(() => new Response("Hello, Deno!"), { port: [1] });
Drag options to blanks, or click blank then click option'
A8080
B5000
C80
D3000
Attempts:
3 left
💡 Hint
Common Mistakes
Using port 80 without proper permissions.
Choosing a port number that might be blocked or reserved.
3fill in blank
hard

Fix the error in the code to correctly read environment variables in Deno.

Deno
const dbPassword = Deno.[1].get("DB_PASSWORD");
Drag options to blanks, or click blank then click option'
Aenvironment
Benv
Cenvs
DgetEnv
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names like 'envs' or 'environment'.
Trying to call a method instead of accessing a property.
4fill in blank
hard

Fill both blanks to create a secure file read function that handles errors in Deno.

Deno
async function readConfig(path) {
  try {
    const data = await Deno.[1](path, { [2]: "utf8" });
    return data;
  } catch {
    return null;
  }
}
Drag options to blanks, or click blank then click option'
AreadTextFile
BreadFile
Cencoding
Dmode
Attempts:
3 left
💡 Hint
Common Mistakes
Using readFile which returns bytes, not text.
Using incorrect option keys like 'mode' instead of 'encoding'.
5fill in blank
hard

Fill all three blanks to create a Deno server that logs requests and responds with JSON.

Deno
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] } });
});
Drag options to blanks, or click blank then click option'
Alog
Bstringify
C"application/json"
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.error instead of console.log.
Forgetting to stringify the JSON object.
Setting wrong content type header.

Practice

(1/5)
1. Why is it important to plan permissions carefully when deploying a Deno app to production?
easy
A. Because Deno restricts access to files, network, and environment by default for security.
B. Because Deno automatically grants all permissions to any script.
C. Because permissions do not affect Deno apps in production.
D. Because permissions only matter during development, not in production.

Solution

  1. Step 1: Understand Deno's default security model

    Deno runs scripts with no permissions by default to protect your system.
  2. Step 2: Recognize the need for explicit permission granting in production

    In production, you must carefully grant only needed permissions to avoid security risks.
  3. Final Answer:

    Because Deno restricts access to files, network, and environment by default for security. -> Option A
  4. Quick Check:

    Default security = careful permission planning [OK]
Hint: Remember: Deno locks down permissions by default [OK]
Common Mistakes:
  • Assuming Deno grants all permissions automatically
  • Ignoring permissions in production
  • Thinking permissions only matter during development
2. Which of the following is the correct way to run a Deno script with network access permission?
easy
A. deno run --allownetwork script.ts
B. deno run --net-allow script.ts
C. deno run --enable-network script.ts
D. deno run --allow-net script.ts

Solution

  1. Step 1: Recall Deno's permission flags syntax

    Deno uses flags like --allow-net to grant network access.
  2. Step 2: Identify the correct flag from options

    Only --allow-net matches Deno's official permission flag syntax.
  3. Final Answer:

    deno run --allow-net script.ts -> Option D
  4. Quick Check:

    Correct flag syntax = --allow-net [OK]
Hint: Look for exact permission flag syntax with dashes [OK]
Common Mistakes:
  • Using incorrect flag names like --net-allow
  • Combining words without dashes
  • Assuming permission flags are optional
3. Consider this Deno code snippet:
try {
  const data = await Deno.readTextFile('config.json');
  console.log('Config loaded:', data);
} catch (error) {
  console.error('Failed to load config:', error.message);
}

What will happen if the file config.json does not exist and the script is run with deno run --allow-read script.ts?
medium
A. The catch block will run and print an error message.
B. The script will crash with an uncaught error.
C. The script will print 'Config loaded:' with empty data.
D. The script will silently ignore the error and continue.

Solution

  1. Step 1: Understand try-catch behavior in async file reading

    If the file is missing, Deno.readTextFile throws an error caught by catch.
  2. Step 2: Analyze the catch block's effect

    The catch block logs 'Failed to load config:' plus the error message.
  3. Final Answer:

    The catch block will run and print an error message. -> Option A
  4. Quick Check:

    Missing file triggers catch block [OK]
Hint: Missing file triggers catch block error handling [OK]
Common Mistakes:
  • Expecting the script to crash without catch
  • Assuming empty string is returned for missing file
  • Thinking error is ignored silently
4. You have this Deno script:
const data = await Deno.readTextFile('data.txt');
console.log(data);

When running deno run script.ts without any flags, what error will you get?
medium
A. SyntaxError: Unexpected token
B. PermissionDenied: read access to "data.txt" is not allowed
C. ReferenceError: Deno is not defined
D. No error, script runs fine

Solution

  1. Step 1: Recall Deno's default permission restrictions

    Deno denies file read access unless --allow-read is given.
  2. Step 2: Identify the error from missing permission

    Running without --allow-read causes a PermissionDenied error.
  3. Final Answer:

    PermissionDenied: read access to "data.txt" is not allowed -> Option B
  4. Quick Check:

    Missing --allow-read causes PermissionDenied [OK]
Hint: No --allow-read means PermissionDenied error [OK]
Common Mistakes:
  • Expecting syntax or reference errors
  • Assuming script runs without permissions
  • Confusing permission errors with runtime errors
5. You want to build a Deno app that reads a config file, fetches data from an API, and writes logs to a file. Which architecture approach best ensures security and maintainability in production?
hard
A. Grant all permissions globally and write all code in one file.
B. Run the app without permissions and rely on user input for data.
C. Use modular code, grant only needed permissions per module, and handle errors properly.
D. Avoid error handling to keep code simple and grant all permissions at runtime.

Solution

  1. Step 1: Consider security by limiting permissions

    Grant only the permissions each module needs to reduce risk.
  2. Step 2: Organize code modularly and handle errors

    Modular code improves maintainability; error handling improves reliability.
  3. Final Answer:

    Use modular code, grant only needed permissions per module, and handle errors properly. -> Option C
  4. Quick Check:

    Modular + limited permissions + error handling = best practice [OK]
Hint: Modular code + least permissions + error handling wins [OK]
Common Mistakes:
  • Granting all permissions globally
  • Ignoring error handling
  • Putting all code in one file
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard