0
0
Node.jsframework~20 mins

What is Node.js in Node.js - Practice Questions & Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Node.js Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is Node.js primarily used for?

Node.js is a popular tool in software development. What is its main use?

AWriting HTML code to structure web pages.
BRunning JavaScript code on the server side to build web servers and backend services.
CDesigning database schemas and managing data storage.
DCreating stylesheets for web pages to control layout and colors.
Attempts:
2 left
💡 Hint

Think about where JavaScript usually runs and what Node.js changes about that.

component_behavior
intermediate
2:00remaining
What does this Node.js code output?

Consider this Node.js code snippet. What will it print to the console?

Node.js
console.log(typeof process);
A"object"
B"undefined"
C"function"
D"string"
Attempts:
2 left
💡 Hint

Think about what process is in Node.js.

📝 Syntax
advanced
2:00remaining
Which option correctly imports the 'fs' module in Node.js ES modules?

Node.js supports different module systems. Which code correctly imports the built-in 'fs' module using ES module syntax?

Aimport * as fs from 'fs';
Bconst fs = require('fs');
Cimport { fs } from 'fs';
Dimport fs from 'fs';
Attempts:
2 left
💡 Hint

ES modules use import statements. Think about how to import all exports as one object.

state_output
advanced
2:00remaining
What is the output of this asynchronous Node.js code?

Look at this Node.js code using setTimeout. What will it print?

Node.js
console.log('Start');
setTimeout(() => console.log('Inside timeout'), 0);
console.log('End');
A"Start" then "Inside timeout" then "End"
B"Inside timeout" then "Start" then "End"
C"Start" then "End" then "Inside timeout"
D"End" then "Start" then "Inside timeout"
Attempts:
2 left
💡 Hint

Remember how JavaScript handles asynchronous callbacks with the event loop.

🔧 Debug
expert
2:00remaining
Which option causes a runtime error in this Node.js code?

Given this code snippet, which option will cause a runtime error when executed?

Node.js
import * as fs from 'fs';

fs.readFile('nonexistent.txt', 'utf8', (err, data) => {
  if (err) throw err;
  console.log(data);
});
AThe code will silently fail without any output or error.
BThe code will print an empty string because the file is empty.
CThe code will print 'undefined' because the callback parameters are incorrect.
DThe file 'nonexistent.txt' does not exist, so the callback receives an error and throws it, causing a runtime error.
Attempts:
2 left
💡 Hint

Think about what happens when you try to read a file that does not exist.