Challenge - 5 Problems
Deno Permission Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediateUnderstanding Deno permission prompts
What happens when you run a Deno script that tries to read a file without the
--allow-read flag?Deno
console.log(await Deno.readTextFile("example.txt"));
Attempts:
2 left
💡 Hint
Think about Deno's security model and how it handles permissions by default.
✗ Incorrect
Deno requires explicit permission flags for file system access. Without
--allow-read, it throws a runtime error denying access.❓ component_behavior
intermediateBehavior of
Deno.permissions.request()What is the output of this code snippet if the user denies the permission request?
Deno
const status = await Deno.permissions.request({ name: "read", path: "./data.txt" }); console.log(status.state);
Attempts:
2 left
💡 Hint
Consider what the
request() method returns based on user action.✗ Incorrect
If the user denies the permission prompt,
request() returns a status object with state set to "denied".📝 Syntax
advancedCorrect usage of
Deno.permissions.query()Which option correctly queries if the script has write permission to the current directory?
Attempts:
2 left
💡 Hint
Check the official Deno permissions API for the correct object shape.
✗ Incorrect
Deno.permissions.query() accepts a descriptor with name and optionally path for filesystem permissions like write. To check access to the current directory specifically, use { name: "write", path: "." }.🔧 Debug
advancedDebugging permission error in Deno script
A Deno script tries to listen on port 8080 but fails with a permission error. Which option explains the cause?
Deno
import { serve } from "https://deno.land/std/http/server.ts"; serve(() => new Response("Hello"), { port: 8080 });
Attempts:
2 left
💡 Hint
Consider what permission is needed to open network sockets in Deno.
✗ Incorrect
Deno requires
--allow-net to open network ports. Without it, a permission error occurs.❓ state_output
expertPermission state after multiple requests
Given this code, what is the final output if the user first denies and then grants the permission when prompted again?
Deno
const first = await Deno.permissions.request({ name: "read" }); const second = await Deno.permissions.request({ name: "read" }); console.log(`${first.state},${second.state}`);
Attempts:
2 left
💡 Hint
Think about how Deno caches permission decisions and how multiple requests behave.
✗ Incorrect
Deno caches permission decisions. The first
request() prompts the user (denied), returning "denied". The second request() returns the cached "denied" state without prompting again.