Challenge - 5 Problems
Deno File System Permissions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediateWhat happens when reading a file without --allow-read?
Consider this Deno script that tries to read a file named
data.txt. What will be the output or error when running it without the --allow-read flag?Deno
const data = await Deno.readTextFile('data.txt'); console.log(data);
Attempts:
2 left
💡 Hint
Think about what Deno requires to access files for reading.
✗ Incorrect
Deno enforces permissions strictly. Without --allow-read, any attempt to read files causes a PermissionDenied error.
❓ state_output
intermediateWhat is the output after writing a file with --allow-write?
Given this Deno script that writes text to
output.txt and then reads it back, what will be printed when run with --allow-write and --allow-read?Deno
await Deno.writeTextFile('output.txt', 'Hello Deno!'); const content = await Deno.readTextFile('output.txt'); console.log(content);
Attempts:
2 left
💡 Hint
Both read and write permissions are needed for this script to work.
✗ Incorrect
With both --allow-write and --allow-read flags, the script can write and then read the file, printing the content.
📝 Syntax
advancedWhich command correctly grants read permission only to a specific file?
You want to run a Deno script
app.ts that reads only config.json. Which command correctly grants read permission only to that file?Attempts:
2 left
💡 Hint
The --allow-read flag can take a path to restrict read access.
✗ Incorrect
The correct syntax to allow read access only to config.json is --allow-read=config.json.
🔧 Debug
advancedWhy does this script fail to write despite using --allow-write?
This script tries to write to
logs/app.log but fails with a PermissionDenied error, even though the command includes --allow-write. What is the most likely cause?Deno
await Deno.writeTextFile('logs/app.log', 'Log entry');
Attempts:
2 left
💡 Hint
Check if the permission flag covers the directory path where the file is located.
✗ Incorrect
When restricting write permission to specific paths, the path must include the directory. Missing it causes PermissionDenied.
🧠 Conceptual
expertWhat is the effect of running a Deno script with both --allow-read and --allow-write but no paths specified?
If you run a Deno script with
deno run --allow-read --allow-write app.ts without specifying any paths, what is the scope of file system access granted?Attempts:
2 left
💡 Hint
Consider what happens when no path is given with these flags.
✗ Incorrect
Without path restrictions, --allow-read and --allow-write grant full file system read and write access.
