Challenge - 5 Problems
Node.js Built-in Module Mastery in Deno
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediateWhat is the output of this Deno code using Node.js 'path' module?
Consider this Deno script that imports the Node.js 'path' module. What will it print?
Deno
import path from 'node:path'; console.log(path.basename('/foo/bar/baz.txt'));
Attempts:
2 left
💡 Hint
Think about what the basename function returns from a file path.
✗ Incorrect
The basename function returns the last part of a path, which is the file name with extension.
📝 Syntax
intermediateWhich import statement correctly loads the Node.js 'fs' module in Deno?
Deno supports Node.js built-in modules with special import paths. Which option correctly imports the 'fs' module?
Attempts:
2 left
💡 Hint
Deno uses the 'node:' prefix for Node.js built-in modules.
✗ Incorrect
Deno requires the 'node:' prefix to import Node.js built-in modules. The other options are invalid in Deno.
🔧 Debug
advancedWhy does this Deno code throw an error when importing 'node:crypto'?
This code throws an error when run in Deno. What is the cause?
Deno
import crypto from 'node:crypto'; console.log(crypto.randomUUID());
Attempts:
2 left
💡 Hint
Check Deno's Node.js compatibility support and flags.
✗ Incorrect
Deno requires enabling Node.js compatibility or specific flags to use 'node:crypto'. Without them, the import fails.
❓ state_output
advancedWhat is the output of this Deno script using 'node:events' module?
Analyze the output of this code snippet:
Deno
import { EventEmitter } from 'node:events'; const emitter = new EventEmitter(); emitter.on('greet', (name) => console.log(`Hello, ${name}!`)); emitter.emit('greet', 'Alice');
Attempts:
2 left
💡 Hint
EventEmitter triggers the listener when 'emit' is called.
✗ Incorrect
The listener logs 'Hello, Alice!' when the 'greet' event is emitted with 'Alice'.
🧠 Conceptual
expertWhich statement about Node.js built-in module support in Deno is TRUE?
Select the correct statement about how Deno supports Node.js built-in modules.
Attempts:
2 left
💡 Hint
Think about Deno's approach to Node.js compatibility.
✗ Incorrect
Deno supports Node.js built-in modules with the 'node:' prefix and enabling compatibility features or flags.
