The --allow-read flag lets a Deno program read files or directories from the file system. Without it, the program cannot access files for reading.
Click to reveal answer
beginner
What is the purpose of the --allow-write flag in Deno?
The --allow-write flag allows a Deno program to create, modify, or delete files and directories. Without this flag, the program cannot change the file system.
Click to reveal answer
intermediate
Why does Deno require explicit permission flags like --allow-read and --allow-write?
Deno uses permission flags to protect your computer from unsafe code. It asks for permission before reading or writing files, similar to how apps ask for access on your phone.
Click to reveal answer
intermediate
How can you allow a Deno script to read only a specific file?
Use --allow-read=path/to/file to give permission only to that file. This limits the script from reading other files.
Click to reveal answer
beginner
What happens if you try to write a file in Deno without --allow-write permission?
Deno will stop the program and show an error saying it does not have permission to write files. This prevents accidental or harmful changes.
Click to reveal answer
Which flag allows a Deno program to read files?
A--allow-write
B--allow-run
C--allow-net
D--allow-read
✗ Incorrect
The --allow-read flag grants permission to read files.
What does --allow-write NOT allow?
AReading files
BModifying existing files
CDeleting files
DCreating new files
✗ Incorrect
--allow-write allows writing but not reading files.
How do you restrict --allow-read to only one directory?
A--allow-write=./mydir
B--allow-read
C--allow-read=./mydir
D--allow-read=all
✗ Incorrect
You specify the path after --allow-read= to limit access.
What happens if you run a Deno script that reads files without --allow-read?
AIt throws a permission error
BIt writes files instead
CIt reads files normally
DIt ignores the read commands
✗ Incorrect
Deno blocks file reading and shows a permission error.
Why does Deno use permission flags like --allow-read?
ATo speed up file access
BTo protect your computer from unsafe code
CTo make code shorter
DTo allow network access
✗ Incorrect
Permission flags protect your computer by controlling what code can do.
Explain how --allow-read and --allow-write control file system access in Deno.
Think about what each flag lets the program do with files.
You got /4 concepts.
Describe what happens if a Deno script tries to read or write files without the proper permission flags.
Consider Deno's security model and how it protects your system.
You got /4 concepts.
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
Step 1: Understand the purpose of --allow-read
This flag grants permission to read files or folders.
Step 2: Compare with other flags
--allow-write is for writing, not reading. Network access is unrelated.
Final Answer:
Allows the program to read files or folders specified. -> Option A
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
Step 1: Recall Deno command syntax
The flags come immediately after deno run and before the script name.
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.
Final Answer:
deno run --allow-write app.ts -> Option D
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
Step 1: Understand default permissions
Without --allow-read, Deno denies file reading for safety.
Step 2: Predict script behavior
Trying to read data.txt without permission causes a runtime error.
Final Answer:
The script throws a permission error. -> Option C
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
Step 1: Identify the permission needed
Writing files requires --allow-write, not just --allow-read.
Step 2: Apply correct flag
Run the script with --allow-write to allow file writing.
Final Answer:
Add --allow-write flag when running the script. -> Option A
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
Step 1: Understand fine-grained permissions
Using --allow-read=path and --allow-write=path limits access to specific files.
Step 2: Match permissions to files
Read permission for input.txt and write permission for output.txt is needed.
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.
Final Answer:
deno run --allow-read=./input.txt --allow-write=./output.txt script.ts -> Option B
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 unknownstrongwhile earning +1 Grip toward your certificate.