Bird
Raised Fist0
Denoframework~20 mins

File system permissions (--allow-read, --allow-write) in Deno - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Deno File System Permissions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What 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);
AThe file content is printed to the console.
BThe script crashes with a SyntaxError.
CThe script runs but prints an empty string.
DA runtime error occurs: PermissionDenied: read access to 'data.txt' is not allowed.
Attempts:
2 left
💡 Hint
Think about what Deno requires to access files for reading.
❓ state_output
intermediate
2:00remaining
What 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);
AHello Deno!
BPermissionDenied error on write operation.
CPermissionDenied error on read operation.
DThe script prints nothing.
Attempts:
2 left
💡 Hint
Both read and write permissions are needed for this script to work.
📝 Syntax
advanced
2:00remaining
Which 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?
Adeno run --allow-read app.ts config.json
Bdeno run --allow-read=./ config.json app.ts
Cdeno run --allow-read=config.json app.ts
Ddeno run --allow-read=config app.ts
Attempts:
2 left
💡 Hint
The --allow-read flag can take a path to restrict read access.
🔧 Debug
advanced
2:00remaining
Why 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');
AThe file 'logs/app.log' is read-only and cannot be overwritten.
BThe --allow-write flag does not include the 'logs' directory path, so permission is denied.
CThe script has a syntax error causing the failure.
DDeno requires --allow-read to write files.
Attempts:
2 left
💡 Hint
Check if the permission flag covers the directory path where the file is located.
🧠 Conceptual
expert
2:00remaining
What 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?
AThe script has full read and write access to the entire file system.
BThe script has no file system access because no paths are specified.
CThe script can only read and write files in the current directory.
DThe script can read files anywhere but write only in the current directory.
Attempts:
2 left
💡 Hint
Consider what happens when no path is given with these flags.

Practice

(1/5)
1. What does the --allow-read flag do when running a Deno program?
easy
A. Allows the program to read files or folders specified.
B. Allows the program to write or modify files.
C. Blocks the program from accessing the network.
D. Runs the program without any permissions.

Solution

  1. Step 1: Understand the purpose of --allow-read

    This flag grants permission to read files or folders.
  2. Step 2: Compare with other flags

    --allow-write is for writing, not reading. Network access is unrelated.
  3. Final Answer:

    Allows the program to read files or folders specified. -> Option A
  4. Quick Check:

    --allow-read = read permission [OK]
Hint: Read permission means accessing files, not changing them [OK]
Common Mistakes:
  • Confusing read permission with write permission
  • Thinking it controls network access
  • Assuming it grants all permissions
2. Which of the following is the correct way to run a Deno script app.ts with permission to write files?
easy
A. deno run app.ts --allow-write
B. deno run app.ts --allow-read
C. deno --allow-write run app.ts
D. deno run --allow-write app.ts

Solution

  1. Step 1: Recall Deno command syntax

    The flags come immediately after deno run and before the script name.
  2. Step 2: Identify correct flag placement

    deno run --allow-write app.ts is correct; options A and C have wrong order, D uses wrong flag.
  3. Final Answer:

    deno run --allow-write app.ts -> Option D
  4. Quick Check:

    Flags go after deno run [OK]
Hint: Flags come right after 'deno run', before script name [OK]
Common Mistakes:
  • Placing flags after the script name
  • Mixing up --allow-read and --allow-write
  • Putting flags before 'run'
3. Consider this Deno script readfile.ts that reads data.txt and prints its content. What happens if you run deno run readfile.ts without any flags?
medium
A. The script creates data.txt if missing.
B. The script runs and prints the file content.
C. The script throws a permission error.
D. The script runs but prints nothing.

Solution

  1. Step 1: Understand default permissions

    Without --allow-read, Deno denies file reading for safety.
  2. Step 2: Predict script behavior

    Trying to read data.txt without permission causes a runtime error.
  3. Final Answer:

    The script throws a permission error. -> Option C
  4. Quick Check:

    No --allow-read means no file reading [OK]
Hint: No read flag means reading files causes error [OK]
Common Mistakes:
  • Assuming Deno allows reading by default
  • Thinking the file is created automatically
  • Believing the script prints empty content silently
4. You have a Deno script that writes to log.txt. Running deno run --allow-read write.ts causes a permission error when writing. What is the fix?
medium
A. Add --allow-write flag when running the script.
B. Remove --allow-read flag and run without flags.
C. Change the script to read instead of write.
D. Run the script with --allow-net flag.

Solution

  1. Step 1: Identify the permission needed

    Writing files requires --allow-write, not just --allow-read.
  2. Step 2: Apply correct flag

    Run the script with --allow-write to allow file writing.
  3. Final Answer:

    Add --allow-write flag when running the script. -> Option A
  4. Quick Check:

    Write permission needs --allow-write [OK]
Hint: Write needs --allow-write, not --allow-read [OK]
Common Mistakes:
  • Using only --allow-read for writing
  • Removing flags thinking it grants all permissions
  • Confusing network permission with file permission
5. You want to run a Deno script that reads from input.txt and writes to output.txt. Which command correctly grants the minimum permissions needed?
hard
A. deno run --allow-net script.ts
B. deno run --allow-read=./input.txt --allow-write=./output.txt script.ts
C. deno run --allow-write=./input.txt --allow-read=./output.txt script.ts
D. deno run --allow-read --allow-write script.ts

Solution

  1. Step 1: Understand fine-grained permissions

    Using --allow-read=path and --allow-write=path limits access to specific files.
  2. Step 2: Match permissions to files

    Read permission for input.txt and write permission for output.txt is needed.
  3. Step 3: Check options

    deno run --allow-read=./input.txt --allow-write=./output.txt script.ts correctly assigns read to input and write to output. deno run --allow-read --allow-write script.ts grants full access, which is more than needed. deno run --allow-write=./input.txt --allow-read=./output.txt script.ts swaps permissions. deno run --allow-net script.ts is unrelated.
  4. Final Answer:

    deno run --allow-read=./input.txt --allow-write=./output.txt script.ts -> Option B
  5. Quick Check:

    Grant only needed file permissions [OK]
Hint: Use path-limited flags to grant minimal permissions [OK]
Common Mistakes:
  • Granting full read/write when only specific files needed
  • Swapping read and write paths
  • Using unrelated flags like --allow-net
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