It grants the Deno program permission to access the network, allowing it to make HTTP requests or open sockets.
Click to reveal answer
intermediate
How can you restrict network access to only specific domains using --allow-net?
You can specify domains or IPs after --allow-net, like --allow-net=example.com,api.example.com, to allow network access only to those addresses.
Click to reveal answer
beginner
What happens if you run a Deno script that tries to access the network without --allow-net?
Deno will block the network request and throw a permission error, preventing the script from accessing the network.
Click to reveal answer
beginner
Why does Deno require explicit network permissions like --allow-net?
To protect users by default, Deno restricts network access so scripts can't connect to the internet or local network without permission, improving security.
Click to reveal answer
intermediate
Can you combine --allow-net with other permission flags in Deno? Give an example.
Yes, for example: deno run --allow-net --allow-read script.ts allows network access and file reading in the same run.
Click to reveal answer
What is the default network access behavior in Deno without --allow-net?
ANetwork access is allowed
BNetwork access is blocked
COnly localhost access is allowed
DNetwork access is logged but allowed
✗ Incorrect
Deno blocks network access by default unless --allow-net is specified.
How do you allow network access only to example.com in Deno?
A<code>--allow-net=example.com</code>
B<code>--allow-net</code> alone
C<code>--allow-net=*</code>
D<code>--allow-net=localhost</code>
✗ Incorrect
Specifying the domain after --allow-net restricts access to that domain only.
Which command runs a script with network and file read permissions?
Adeno run script.ts
Bdeno run --allow-net script.ts
Cdeno run --allow-read script.ts
Ddeno run --allow-net --allow-read script.ts
✗ Incorrect
You can combine multiple permission flags to grant several permissions at once.
If a script tries to fetch data from the internet without --allow-net, what happens?
AThe fetch fails with a permission error
BThe fetch succeeds silently
CThe script crashes without error
DThe fetch is delayed until permission is granted
✗ Incorrect
Deno enforces permissions strictly and throws an error if network access is denied.
Why is explicit network permission important in Deno?
AIt allows automatic retries on failure
BIt speeds up network requests
CIt improves security by preventing unauthorized network access
DIt enables logging of network traffic
✗ Incorrect
Explicit permissions help protect users from malicious or unintended network activity.
Explain how the --allow-net flag controls network access in Deno and why it is important.
Think about what happens if you don't use the flag and why Deno needs it.
You got /4 concepts.
Describe how you would run a Deno script that needs to fetch data from a specific website and read local files.
Consider combining permissions in one command line.
You got /4 concepts.
Practice
(1/5)
1. What does the --allow-net flag do when running a Deno program?
easy
A. It allows the program to access the network.
B. It disables all network access for the program.
C. It grants permission to read local files.
D. It enables debugging mode for the program.
Solution
Step 1: Understand the purpose of --allow-net
This flag is used to grant network access to a Deno program, which is otherwise restricted for security.
Step 2: Compare options with the flag's function
Only "It allows the program to access the network." correctly states that --allow-net allows network access. Other options describe unrelated permissions or features.
Final Answer:
It allows the program to access the network. -> Option A
Quick Check:
Network permission = Allow network access [OK]
Hint: Remember: --allow-net means allow network access [OK]
Common Mistakes:
Confusing --allow-net with file permissions
Thinking it disables network access
Mixing it up with debugging flags
2. Which of the following is the correct way to allow network access only to example.com when running a Deno script named app.ts?
easy
A. deno run app.ts --allow-net=example.com
B. deno run --allow-net app.ts example.com
C. deno run --allow-net=example.com app.ts
D. deno run --allow-net example.com app.ts
Solution
Step 1: Identify correct flag syntax for domain restriction
The correct syntax is --allow-net=domain placed before the script name.
Step 2: Check command order and placement
deno run --allow-net=example.com app.ts correctly places --allow-net=example.com before app.ts. Other options have incorrect order or syntax.
Final Answer:
deno run --allow-net=example.com app.ts -> Option C
Quick Check:
Correct flag syntax = deno run --allow-net=example.com app.ts [OK]
Hint: Put --allow-net=domain before script name [OK]
Common Mistakes:
Placing domain after script name
Using space instead of '=' between flag and domain
Confusing permission error with URL or reference errors
Ignoring domain restrictions in --allow-net
5. You want to run a Deno script that fetches data from both api.example.com and data.service.org. Which command correctly grants network access to both domains using a single --allow-net flag?
hard
A. deno run --allow-net=api.example.com --allow-net=data.service.org app.ts
B. deno run --allow-net=api.example.com,data.service.org app.ts
C. deno run --allow-net app.ts api.example.com data.service.org
D. deno run --allow-net=api.example.com;data.service.org app.ts
Solution
Step 1: Understand multiple domain syntax for --allow-net
Deno accepts multiple domains separated by commas in a single --allow-net flag.
Step 2: Evaluate each option's correctness
deno run --allow-net=api.example.com,data.service.org app.ts uses comma-separated domains correctly. deno run --allow-net=api.example.com --allow-net=data.service.org app.ts repeats the flag (not a single flag). deno run --allow-net app.ts api.example.com data.service.org misplaces domains as arguments. deno run --allow-net=api.example.com;data.service.org app.ts uses semicolon which is incorrect.
Final Answer:
deno run --allow-net=api.example.com,data.service.org app.ts -> Option B
Quick Check:
Multiple domains = comma-separated in one flag [OK]
Hint: Use commas to list multiple domains in --allow-net [OK]
Common Mistakes:
Using multiple --allow-net flags
Separating domains with semicolons
Placing domains after script name
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.