Challenge - 5 Problems
Npm Import 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 importing an npm package?
Consider this Deno script that imports the lodash package from npm and uses its
capitalize function. What will be printed when running this code?Deno
import { capitalize } from "npm:lodash"; console.log(capitalize("hello world"));
Attempts:
2 left
💡 Hint
Think about what the
capitalize function does to the first letter only.✗ Incorrect
The lodash
capitalize function converts the first character to uppercase and the rest to lowercase. So "hello world" becomes "Hello world".📝 Syntax
intermediateWhich import statement correctly imports the
express package in Deno from npm?You want to use the
express package from npm in your Deno project. Which import statement is syntactically correct?Attempts:
2 left
💡 Hint
Deno uses ES module syntax and supports default imports from npm packages.
✗ Incorrect
Deno supports ES module syntax and allows default imports from npm packages using the "npm:" prefix. Option D uses the correct default import syntax.
🔧 Debug
advancedWhy does this Deno code fail to import the
chalk npm package?This Deno code tries to import
chalk from npm but throws an error. What is the most likely cause?Deno
import chalk from "npm:chalk"; console.log(chalk.green("Success!"));
Attempts:
2 left
💡 Hint
Check if the npm package supports ESM or if the version is compatible with Deno's npm loader.
✗ Incorrect
Some npm packages like chalk have versions that do not fully support ESM or have dependencies incompatible with Deno's npm loader. Using an incompatible version causes import errors.
❓ state_output
advancedWhat is the output of this Deno script importing and using
uuid from npm?This Deno script imports the
v4 function from the uuid npm package and logs a generated UUID. What will be the output format?Deno
import { v4 } from "npm:uuid"; console.log(v4());
Attempts:
2 left
💡 Hint
UUID v4 generates a random unique identifier string in a specific format.
✗ Incorrect
The v4 function from uuid generates a random UUID string in the format of 8-4-4-4-12 hexadecimal characters separated by dashes.
🧠 Conceptual
expertWhich statement about importing npm packages in Deno is TRUE?
Select the correct statement about how Deno handles importing npm packages.
Attempts:
2 left
💡 Hint
Think about Deno's npm support and compatibility with CommonJS packages.
✗ Incorrect
Deno supports importing npm packages using the "npm:" prefix, but not all packages work out of the box due to differences between CommonJS and ES modules. Some packages require adjustments.
