Challenge - 5 Problems
Node.js Script Runner Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:00remaining
What is the output when running this Node.js script?
Consider the following Node.js script saved as
script.js. What will be printed to the console when you run node script.js?Node.js
console.log('Hello from Node.js!');Attempts:
2 left
💡 Hint
Think about what console.log does in Node.js.
✗ Incorrect
The script prints the string inside console.log to the console when run with node.
❓ Predict Output
intermediate1:30remaining
What happens if you run a script with a syntax error?
Given this Node.js script saved as
error.js, what will happen when you run node error.js?Node.js
console.log('Missing quote);Attempts:
2 left
💡 Hint
Look carefully at the quotes in the code.
✗ Incorrect
The missing closing quote causes a syntax error preventing the script from running.
❓ component_behavior
advanced2:00remaining
What will be the output of this asynchronous Node.js script?
Examine the following script saved as
async.js. What will be printed when running node async.js?Node.js
console.log('Start'); setTimeout(() => console.log('Timeout'), 0); console.log('End');
Attempts:
2 left
💡 Hint
Remember how setTimeout works with zero delay.
✗ Incorrect
setTimeout schedules the callback after the current call stack finishes, so 'Timeout' prints last.
🔧 Debug
advanced2:00remaining
Why does this Node.js script throw an error when run?
Look at this script saved as
errorCheck.js. When running node errorCheck.js, it throws an error. What is the cause?Node.js
const fs = require('fs'); fs.readFile('nonexistent.txt', (err, data) => { if (err) throw err; console.log(data.toString()); });
Attempts:
2 left
💡 Hint
Check what happens when reading a file that is missing.
✗ Incorrect
The callback receives an error object because the file is missing, and the script throws it.
📝 Syntax
expert2:30remaining
Which option correctly runs a Node.js script with ES module syntax?
You have a script
module.mjs using ES module syntax with import. How do you run it with Node.js?Node.js
import fs from 'fs'; console.log('Module loaded');
Attempts:
2 left
💡 Hint
Modern Node.js supports ES modules with .mjs extension by default.
✗ Incorrect
Node.js runs .mjs files as ES modules without extra flags in recent versions.