Challenge - 5 Problems
Deno Node.js Shim Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediateHow does Deno's Node.js shim handle the 'fs' module?
In Deno, when using the Node.js 'fs' shim, what happens if you call
fs.readFileSync on a file path? Assume the file exists and is readable.Deno
import * as fs from "https://deno.land/std/node/fs.ts"; const content = fs.readFileSync("./example.txt", "utf8"); console.log(content);
Attempts:
2 left
💡 Hint
Think about how Deno's Node.js shims aim to mimic Node.js APIs synchronously where possible.
✗ Incorrect
Deno's Node.js 'fs' shim implements synchronous methods like readFileSync to behave similarly to Node.js, returning the file content directly as a string or buffer.
📝 Syntax
intermediateCorrect import syntax for Deno Node.js 'path' shim
Which import statement correctly imports the Node.js 'path' module shim in Deno?
Attempts:
2 left
💡 Hint
Deno uses ES module syntax and the Node.js shims export all functions as named exports.
✗ Incorrect
The Node.js shims in Deno export all functions as named exports, so importing everything as an object with * as syntax is correct.
🔧 Debug
advancedWhy does this Deno code using Node.js 'crypto' shim fail?
Consider this Deno code snippet:
import { randomBytes } from "https://deno.land/std/node/crypto.ts";
const buf = randomBytes(16);
console.log(buf);
Why might this code throw an error in Deno?
Deno
import { randomBytes } from "https://deno.land/std/node/crypto.ts"; const buf = randomBytes(16); console.log(buf);
Attempts:
2 left
💡 Hint
Deno has a security model that requires permissions for certain operations.
✗ Incorrect
Deno requires the --allow-hrtime permission for some crypto operations. Without permissions, it throws a permission error.
❓ state_output
advancedWhat is the output of this Deno code using Node.js 'events' shim?
Analyze the following code and determine what it prints to the console:
Deno
import { EventEmitter } from "https://deno.land/std/node/events.ts"; const emitter = new EventEmitter(); emitter.on("greet", (name) => { console.log(`Hello, ${name}!`); }); emitter.emit("greet", "Alice"); emitter.emit("greet", "Bob");
Attempts:
2 left
💡 Hint
The events shim mimics Node.js EventEmitter behavior.
✗ Incorrect
The EventEmitter shim in Deno works like Node.js, so the 'greet' event triggers the listener twice with the given names.
🧠 Conceptual
expertWhich Node.js API is NOT fully supported by Deno shims and why?
Among the following Node.js core modules, which one is known to have incomplete or partial support in Deno's Node.js shims, and what is the main reason?
Attempts:
2 left
💡 Hint
Consider Deno's security model and API design differences from Node.js.
✗ Incorrect
Deno's 'net' module shim is partial because Deno's networking APIs differ and it restricts low-level socket operations for security and design reasons.
