19 questions from the Node.js Fundamentals: Modules, Async and Servers course, each with the correct answer and an explanation. Try to answer before you open the answer.
Module 12: Putting It Together
10. Why does npm version patch matter before publishing an update?
- npm refuses to publish a version number that already exists on the registry
- It compiles the code
- It deletes the previous version
- It uploads the code automatically
Show answer
Answer: npm refuses to publish a version number that already exists on the registry
The registry treats each version as immutable — you must bump the number to publish new changes.
Lesson: Publishing to npm
11. What makes Node able to handle many connections with one thread?
- One thread per request
- Compiling to C++
- Non-blocking I/O and the event loop
- A built-in database
Show answer
Answer: Non-blocking I/O and the event loop
Waiting I/O is handed off while the loop serves other work.
Lesson: Publishing to npm
12. Which field enables ES module syntax in package.json?
- "main": "esm"
- "es": true
- "import": "all"
- "type": "module"
Show answer
Answer: "type": "module"
Set type to module (or use .mjs).
Lesson: Publishing to npm
13. What does ^4.19.2 allow?
- Minor and patch updates below 5.0.0
- Only patch updates
- Major updates
- No updates
Show answer
Answer: Minor and patch updates below 5.0.0
Caret allows compatible updates within the same major version.
Lesson: Publishing to npm
14. Why use fs/promises inside a server handler?
- It is shorter
- It does not block the event loop
- It encrypts files
- It needs no import
Show answer
Answer: It does not block the event loop
Async file calls let other requests continue.
Lesson: Publishing to npm
15. Which method connects a readable stream to a writable stream with backpressure?
- push
- emit
- pipe (or pipeline)
- spawn
Show answer
Answer: pipe (or pipeline)
pipe and stream.pipeline manage flow control for you.
Lesson: Publishing to npm
16. How do you run independent async calls together?
- Await them one by one
- setTimeout
- process.exit
- Promise.all
Show answer
Answer: Promise.all
Promise.all runs them concurrently and waits for all.
Lesson: Publishing to npm
17. What should you do after an uncaughtException?
- Log it and exit the process
- Ignore it
- Retry forever
- Delete node_modules
Show answer
Answer: Log it and exit the process
The process may be in an unknown state, so exit and let a supervisor restart it.
Lesson: Publishing to npm
18. Which Node module moves CPU-heavy work off the main thread?
- path
- worker_threads
- os
- dotenv
Show answer
Answer: worker_threads
Worker threads keep the event loop responsive.
Lesson: Publishing to npm
19. Which command runs Node's built-in tests?
- node --test
- npm install test
- node --check
- node --lint
Show answer
Answer: node --test
`node --test` discovers and runs test files with the built-in runner.
Lesson: Testing with node:test