Node.js interview questions

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 1: Getting Started

1. What does REPL stand for?

  1. Run-Execute-Process Line
  2. Remote Execution Protocol Layer
  3. Rapid Event Preview Loop
  4. Read-Eval-Print Loop
Show answer

Answer: Read-Eval-Print Loop

It reads your input, evaluates it, prints the result, and loops.

Lesson: Running Scripts & the REPL

Module 2: Modules

2. Which prefix explicitly marks a Node built-in module?

  1. node:
  2. npm:
  3. ./
  4. pkg:
Show answer

Answer: node:

`node:fs`, `node:path` etc. make it unambiguous that you mean the built-in, not a same-named package.

Lesson: Built-in, Third-Party & Local Modules

Module 3: NPM

3. Which two script names can you run without typing `run`?

  1. dev and build
  2. start and test
  3. install and stop
  4. lint and format
Show answer

Answer: start and test

`npm start` and `npm test` are shortcuts baked into npm; every other script name needs `npm run <name>`.

Lesson: npm Scripts

Module 4: Core Modules

4. Why avoid `readFileSync` inside a request handler?

  1. It throws on missing files
  2. It cannot read text files
  3. It blocks the event loop for every other request
  4. It only works on Windows
Show answer

Answer: It blocks the event loop for every other request

Sync fs calls freeze Node's single thread — no other request is served until the read finishes.

Lesson: The fs Module

Module 5: Events & Streams

5. Why prefer streams over readFile for a very large file?

  1. Streams are always faster to write code for
  2. readFile cannot read files over 1KB
  3. Streams never use memory
  4. Streams process data in chunks instead of loading it all into memory
Show answer

Answer: Streams process data in chunks instead of loading it all into memory

Streams keep memory usage low and let you start processing before the whole file has arrived.

Lesson: Streams

Module 6: Building a Server

6. What does res.end() do?

  1. Sends the response and closes it
  2. Starts the server
  3. Deletes the request
  4. Installs Express
Show answer

Answer: Sends the response and closes it

`res.end()` finishes sending the response body; no more data can be written to it afterward.

Lesson: The http Module

Module 7: Async Patterns

7. What happens to the rest of Node while one function awaits a Promise?

  1. It freezes completely
  2. It keeps running other work
  3. It restarts the event loop
  4. It exits with an error
Show answer

Answer: It keeps running other work

`await` only pauses the current async function — the event loop is free to handle other events meanwhile.

Lesson: async/await

Module 9: Error Handling

8. Once uncaughtException fires, what's the recommended action?

  1. Ignore it and continue
  2. Retry the failed operation automatically
  3. Log it and exit the process
  4. Silence all errors with an empty handler
Show answer

Answer: Log it and exit the process

After an uncaught exception, app state may be corrupted — log the error and exit rather than limping along.

Lesson: Uncaught Exceptions & Process Events

Module 11: Debugging & Tooling

9. What is the main benefit of nodemon (or node --watch) during development?

  1. It makes the app run faster in production
  2. It replaces the need for testing
  3. It bundles your code for production
  4. It restarts the server automatically on file changes
Show answer

Answer: It restarts the server automatically on file changes

It removes the manual stop-and-restart cycle every time you edit code.

Lesson: Auto-Restart with nodemon

Module 12: Putting It Together

10. Why does npm version patch matter before publishing an update?

  1. npm refuses to publish a version number that already exists on the registry
  2. It compiles the code
  3. It deletes the previous version
  4. 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?

  1. One thread per request
  2. Compiling to C++
  3. Non-blocking I/O and the event loop
  4. 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?

  1. "main": "esm"
  2. "es": true
  3. "import": "all"
  4. "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?

  1. Minor and patch updates below 5.0.0
  2. Only patch updates
  3. Major updates
  4. 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?

  1. It is shorter
  2. It does not block the event loop
  3. It encrypts files
  4. 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?

  1. push
  2. emit
  3. pipe (or pipeline)
  4. 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?

  1. Await them one by one
  2. setTimeout
  3. process.exit
  4. 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?

  1. Log it and exit the process
  2. Ignore it
  3. Retry forever
  4. 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?

  1. path
  2. worker_threads
  3. os
  4. 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?

  1. node --test
  2. npm install test
  3. node --check
  4. node --lint
Show answer

Answer: node --test

`node --test` discovers and runs test files with the built-in runner.

Lesson: Testing with node:test

← Back to the course