What is a key difference between Node.js and Deno regarding module imports?
Deno uses URL-based or relative path imports with file extensions, while Node.js uses package names and relies on a package manager like npm.
Click to reveal answer
beginner
How does Deno handle permissions compared to Node.js?
Deno requires explicit permission flags for file, network, and environment access, improving security by default, unlike Node.js which grants full access by default.
Click to reveal answer
intermediate
Why might you need to change your package management approach when migrating from Node.js to Deno?
Deno does not use npm or package.json; it imports modules directly via URLs or local paths, so you must update dependencies to compatible URLs or use Deno's standard modules.
Click to reveal answer
intermediate
What is a common step to migrate Node.js code using CommonJS modules to Deno?
Rewrite CommonJS require() calls to ES module import statements with explicit file extensions, as Deno supports ES modules natively and does not support require().
Click to reveal answer
beginner
How can you run a Deno script with network access enabled?
Use the command: deno run --allow-net your_script.ts to grant network permissions explicitly.
Click to reveal answer
Which command grants Deno permission to read files?
Adeno run --allow-read script.ts
Bdeno run --allow-file script.ts
Cdeno run --read script.ts
Ddeno run --file-access script.ts
✗ Incorrect
The correct flag to allow file reading in Deno is --allow-read.
How do you import a module in Deno?
Aconst mod = require('mod');
Bimport mod from './mod.ts';
Cimport mod from 'mod';
Dconst mod = import('mod');
✗ Incorrect
Deno requires explicit file extensions and relative or URL paths, so './mod.ts' is correct.
What package manager does Deno use?
Apnpm
Byarn
CNone, it uses direct URL imports
Dnpm
✗ Incorrect
Deno does not use a package manager like npm; it imports modules directly via URLs or local paths.
Which Node.js feature is NOT supported natively in Deno?
ATop-level await
BES modules
CAsync/await
DCommonJS require()
✗ Incorrect
Deno does not support CommonJS require(); it uses ES module imports instead.
What is the default security model of Deno?
ANo access unless explicitly allowed
BAccess only to network
CFull access to system resources
DAccess only to environment variables
✗ Incorrect
Deno requires explicit permission flags to access files, network, or environment, enhancing security.
Explain the main steps to migrate a Node.js project to Deno.
Think about module syntax, dependencies, permissions, and security.
You got /4 concepts.
Describe how Deno's permission system improves security compared to Node.js.
Focus on what Deno asks you to allow before running code.
You got /4 concepts.
Practice
(1/5)
1. Which of the following is a key difference when migrating a Node.js project to Deno?
easy
A. Deno uses CommonJS modules by default.
B. Deno uses URL imports instead of npm packages.
C. Deno requires no code changes from Node.js.
D. Deno automatically grants all permissions to the code.
Solution
Step 1: Understand module import differences
Node.js uses npm packages imported by name, while Deno uses direct URL imports.
Step 2: Check permission handling and module system
Deno requires explicit permission grants and uses ES modules, not CommonJS.
Final Answer:
Deno uses URL imports instead of npm packages. -> Option B
Quick Check:
Module import style = D [OK]
Hint: Remember: Deno imports modules via URLs, not npm names. [OK]
Common Mistakes:
Assuming Deno uses npm packages directly
Thinking Deno grants permissions automatically
Believing Node.js code runs unchanged in Deno
2. Which syntax correctly imports the lodash library in Deno?
easy
A. import _ from 'https://cdn.skypack.dev/lodash';
B. const _ = require('lodash');
C. import _ from 'lodash';
D. import _ from 'npm:lodash';
Solution
Step 1: Identify Deno import style
Deno imports modules using URLs, not package names or require().
Step 2: Check each option
import _ from 'https://cdn.skypack.dev/lodash'; uses a valid URL import from a CDN, which is correct for Deno.
Final Answer:
import _ from 'https://cdn.skypack.dev/lodash'; -> Option A
Quick Check:
URL import syntax = C [OK]
Hint: Use full URLs for imports in Deno, not package names. [OK]
Common Mistakes:
Using require() which is Node.js only
Importing by package name without URL
Using npm: prefix which Deno does not support
3. What will be the output when running this Deno script?
import { readFileStr } from 'https://deno.land/std/fs/mod.ts';
const data = await readFileStr('./file.txt');
console.log(data.trim());
Assuming file.txt contains " Hello Deno \n".
medium
A. Error: readFileStr is not a function
B. Hello Deno
C. undefined
D. oneD olleH
Solution
Step 1: Understand readFileStr usage
The function readFileStr was deprecated and removed in recent versions of Deno std library. Using it will cause an error.
Step 2: Analyze output
Since readFileStr is not a function, the script will throw an error.
Final Answer:
Error: readFileStr is not a function -> Option A
Quick Check:
Function availability = D [OK]
Hint: Use Deno.readTextFile or Deno.readTextFileSync instead of deprecated readFileStr. [OK]
Common Mistakes:
Expecting original spaces without trim()
Confusing readFileStr with non-existent function
Ignoring await causing undefined
4. You migrated a Node.js script to Deno but get this error: PermissionDenied: read access to './data.json' is not allowed. How do you fix it?
medium
A. Install the missing npm package for file access.
B. Change the file path to an absolute path.
C. Run the script with deno run --allow-read flag.
D. Use require() instead of import.
Solution
Step 1: Understand Deno's permission model
Deno requires explicit permission flags to access files for security.
Step 2: Apply correct permission flag
Using --allow-read grants read access to files, fixing the error.
Final Answer:
Run the script with deno run --allow-read flag. -> Option C
Quick Check:
Permission error fix = A [OK]
Hint: Add --allow-read flag to grant file read permission. [OK]
Common Mistakes:
Ignoring permission flags in Deno
Trying to fix path instead of permissions
Using Node.js require() which Deno disallows
5. You have this Node.js code snippet using the 'fs' module:
const fs = require('fs');
const data = fs.readFileSync('./info.txt', 'utf8');
console.log(data);
How should you rewrite it in Deno to read the file synchronously?
hard
A. const data = Deno.readFile('./info.txt'); console.log(data);
B. const data = await Deno.readTextFile('./info.txt'); console.log(data);
C. import fs from 'https://deno.land/std/fs/mod.ts'; const data = fs.readFileSync('./info.txt');
D. const data = Deno.readTextFileSync('./info.txt'); console.log(data);
Solution
Step 1: Identify synchronous file read in Deno
Deno provides readTextFileSync() for synchronous text file reading.
Step 2: Compare options
const data = Deno.readTextFileSync('./info.txt'); console.log(data); correctly uses readTextFileSync and logs the data synchronously.
Final Answer:
const data = Deno.readTextFileSync('./info.txt'); console.log(data); -> Option D
Quick Check:
Synchronous file read in Deno = A [OK]
Hint: Use Deno.readTextFileSync for sync file reading like Node's readFileSync. [OK]
Common Mistakes:
Using await with synchronous functions
Trying to import Node.js fs module in Deno
Using readFile which returns Uint8Array, not string
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.