Skip to content
tezvyn:

Top 30 Easy Node.js & Express Interview Questions and Answers for Freshers

30 easy multiple-choice Node.js & Express interview questions, the ones an interviewer opens with: definitions, everyday syntax, and the quick checks that you have really used it. They come from 30 bites in the Node.js & Express library, the gentlest slice of the 134 Node.js & Express interview questions in the library. Answer them here or read straight down. Every question carries the correct option, why it is correct, and a link to the bite it came from.

Node.js, Express, Fastify, NestJS, Bun, Deno

30 questions. Pick an answer, or open “Show the answer” to read it.

Answers are graded in your browser. Nothing is saved, and no XP or streak is earned here. The app keeps score.

  1. Question 1 of 30

    Which statement best describes how Node.js handles I/O for thousands of concurrent connections?

    Show the answer

    Answer: a · Network sockets are watched by the OS, while blocking tasks like DNS and file reads use a small internal thread pool.

    Node.js relies on the OS kernel to monitor network sockets and notify the event loop when data arrives, while delegating blocking operations like DNS and some file system work to a limited internal thread pool. Distractor D is tempting because Node is famous for non-blocking I/O, but it wrongly assumes every I/O operation can run without thread assistance.

    Read the full bite: How does Node.js handle thousands of connections on one thread?

  2. Question 2 of 30

    Why is it a problem to list a library your source code imports at runtime under devDependencies?

    Show the answer

    Answer: d · A production install that skips devDependencies leaves it missing, causing runtime errors

    Production installs omit devDependencies, so a runtime import placed there will be absent and throw module-not-found. Runtime libraries must live under dependencies.

    Read the full bite: dependencies vs devDependencies in package.json

  3. Question 3 of 30

    What does Node do first when it encounters require('fs')?

    Show the answer

    Answer: a · Matches it against built-in core modules, which take precedence

    Bare specifiers are checked against built-in core modules first; fs is compiled into the binary and resolves without touching node_modules. The package search only runs for non-core bare names.

    Read the full bite: Resolving core vs relative module specifiers

  4. Question 4 of 30

    Which statement about a Promise's state transitions is correct?

    Show the answer

    Answer: a · Once settled as fulfilled or rejected, the state is permanent and cannot change

    Settling is one-way and final; a Promise transitions from pending to exactly one of fulfilled or rejected and stays there. then callbacks run later as microtasks, not synchronously.

    Read the full bite: The three states of a JavaScript Promise

  5. Question 5 of 30

    Why is calling fs.readFileSync inside an Express request handler a problem under concurrent load?

    Show the answer

    Answer: c · It blocks the single event loop thread, stalling all other pending requests

    The sync read blocks the one event loop thread until it finishes, so every other request waits. It is not forbidden and does not spawn threads; the async version uses the libuv pool instead.

    Read the full bite: fs.readFileSync vs fs.readFile

  6. Question 6 of 30

    What does path.join provide that naive string concatenation of path segments does not?

    Show the answer

    Answer: c · Platform-correct separators plus normalization of redundant slashes and segments

    path.join inserts the right separator per OS and normalizes the path. It does not encrypt, speed up reads, or by itself stop traversal attacks, which still require explicit validation.

    Read the full bite: Why use path.join over string concatenation

  7. Question 7 of 30

    In a bare http module server, what is the consequence of never calling res.end inside the request listener?

    Show the answer

    Answer: a · The client connection hangs because the response is never finalized

    res.end finalizes and flushes the response; without it the client waits indefinitely. Node does not auto-complete the response, crash, or retry the request on its own.

    Read the full bite: Minimal HTTP server with the http module

  8. Question 8 of 30

    In a minimal Express app, what does omitting the app.listen call result in?

    Show the answer

    Answer: a · The server never binds to a port, so no requests are served

    app.listen binds the server to a port; without it nothing accepts connections. Express does not pick a random port, throw automatically, or selectively serve routes.

    Read the full bite: Minimal Express Hello World server

  9. Question 9 of 30

    Why is express.static(path.join(__dirname, 'public')) preferred over express.static('public')?

    Show the answer

    Answer: c · A bare relative path resolves against the variable working directory and can break

    A relative path is resolved against the current working directory, which varies by launch context, so the absolute __dirname-based path is reliable. Both forms set caching headers and serve at the same speed.

    Read the full bite: Serving static files in Express

  10. Question 10 of 30

    For the route app.get('/users/:id') hit by /users/42?active=true, which is correct?

    Show the answer

    Answer: a · req.params.id is '42' and req.query.active is 'true'

    Named path segments populate req.params and the query string populates req.query. The id is a route param and active is a query param, so the two objects are not interchangeable.

    Read the full bite: Query params vs route params in Express

  11. Question 11 of 30

    In an Express middleware, what is the consequence of neither sending a response nor calling next?

    Show the answer

    Answer: a · The request hangs indefinitely because nothing advances or ends it

    A middleware must either end the response or call next; doing neither leaves the request stalled forever. Express does not auto-advance, run the next handler, or throw on its own.

    Read the full bite: What is Express middleware

  12. Question 12 of 30

    A teammate posts JSON to your endpoint but req.body is undefined. The route is defined and the client sets Content-Type correctly. What is the most likely cause?

    Show the answer

    Answer: a · express.json() was registered after the route definition

    Middleware runs in registration order, so a parser added after the route never touches that request. body-parser is not required since express.json() is built in.

    Read the full bite: Parse JSON and URL-encoded bodies in Express

  13. Question 13 of 30

    Your logging middleware prints correctly but every request to the server eventually times out with no response. What did the middleware most likely fail to do?

    Show the answer

    Answer: a · Call next() to pass control to the next handler

    A middleware must either send a response or call next(); omitting next() leaves the request hanging. console is global and needs no import, and middleware need not return Promises.

    Read the full bite: Write a request-logging middleware in Express

  14. Question 14 of 30

    Which combination correctly follows REST conventions for creating a new user?

    Show the answer

    Answer: d · POST /users, read fields from req.body, respond 201

    Creation uses POST against the plural collection /users, with input in the body and a 201 Created response. GET must be side-effect free and verbs do not belong in REST URLs.

    Read the full bite: Design an Express route to create a user

  15. Question 15 of 30

    For GET /products/42?sort=price, where do the id 42 and the sort value come from respectively?

    Show the answer

    Answer: b · req.params.id and req.query.sort

    42 is a named route segment captured in req.params, while sort=price is part of the query string in req.query. The body is empty on a typical GET.

    Read the full bite: req.params vs req.query vs req.body in Express

  16. Question 16 of 30

    An API returns 200 OK for every successful response, including resource creation. What semantic information is being lost?

    Show the answer

    Answer: a · That a new resource was created, which 201 (with a Location header) signals

    201 Created communicates that a new resource now exists and where to find it via Location; a generic 200 hides that distinction. Auth, caching, and content type are conveyed by other mechanisms.

    Read the full bite: Status codes for successful POST and GET

  17. Question 17 of 30

    After defining productSchema, which line gives you the constructor used to create and query Product documents?

    Show the answer

    Answer: c · mongoose.model('Product', productSchema)

    mongoose.model compiles a schema into a model, the queryable constructor. new mongoose.Schema defines structure only, and mongoose.connect opens a database connection.

    Read the full bite: Define a Mongoose schema and model

  18. Question 18 of 30

    A user logs in successfully, then requests an admin-only endpoint and is rejected. Which HTTP status best fits, and why?

    Show the answer

    Answer: d · 403 Forbidden, because they are authenticated but lack permission

    The user proved their identity (authentication succeeded) but lacks the required role, which is an authorization failure mapped to 403. 401 would imply missing or invalid credentials.

    Read the full bite: Authentication versus authorization in Express

  19. Question 19 of 30

    An attacker decodes a JWT, edits the role claim to admin, and re-encodes it without the secret. What happens at verification?

    Show the answer

    Answer: d · Verification fails because the signature no longer matches the altered payload

    The signature is a keyed hash over header and payload; altering the payload without the secret makes the recomputed signature mismatch, so verification fails. Base64url is just encoding, not protection, and the payload is not encrypted.

    Read the full bite: JWT structure and how the signature works

  20. Question 20 of 30

    Your POST /login handler reads req.body but it is always undefined. What is the most likely cause?

    Show the answer

    Answer: c · The express.json body-parsing middleware is not mounted

    req.body is populated only when a body-parsing middleware like express.json runs first; without it req.body stays undefined. req.body is synchronous, so awaiting it would not help.

    Read the full bite: Basic presence validation on a POST login route

  21. Question 21 of 30

    You write a test that sends an HTTP request to a route handler which queries a real test database. Which category is this?

    Show the answer

    Answer: a · An integration test, because it exercises the route and database together

    Exercising multiple components together, the route plus a real database, through the API layer is an integration test. It is not a unit test (dependencies are not isolated) and not full E2E (it does not drive the entire deployed system through a client).

    Read the full bite: Unit, integration, and E2E tests explained

  22. Question 22 of 30

    Your Jest test compares the function's returned object using expect(result).toBe(expectedObject) and it fails despite identical contents. Why?

    Show the answer

    Answer: b · toBe checks reference identity, so use toEqual for deep object comparison

    toBe uses Object.is reference equality, so two distinct objects with equal contents are not the same reference and the test fails. toEqual performs a deep structural comparison and is the correct matcher for objects.

    Read the full bite: Writing a basic Jest unit test

  23. Question 23 of 30

    A reviewer says adding Helmet makes the Express app secure. What is the most accurate correction?

    Show the answer

    Answer: d · Helmet sets protective HTTP headers as one defense layer but does not fix application logic or validate input

    Helmet hardens responses with security headers but does no input validation and does not secure application logic. It is defense in depth, not a complete security solution, and it is not a CORS tool.

    Read the full bite: Purpose of Helmet middleware in Express

  24. Question 24 of 30

    In an EJS template, which choice most directly prevents stored XSS when displaying a user-submitted comment?

    Show the answer

    Answer: a · Use the escaping interpolation <%= comment %> so HTML is encoded as text

    The escaping tag converts HTML metacharacters into entities so injected markup renders as text. The raw tag executes the markup, and length validation or table choice does nothing to neutralize script.

    Read the full bite: Preventing XSS when rendering user content in templates

  25. Question 25 of 30

    What is the core advantage of streaming a large file to a client instead of reading it fully into memory first?

    Show the answer

    Answer: a · Memory stays bounded and bytes can start flowing before the whole file is read

    Processing data in chunks keeps memory flat regardless of file size and lowers time-to-first-byte. Streams do not auto-compress, fit data into one packet, or remove the need for error handling.

    Read the full bite: What is a Node.js Stream and why use one

  26. Question 26 of 30

    How does the cluster module improve a Node web server's throughput on a multi-core machine?

    Show the answer

    Answer: d · It forks multiple worker processes sharing one port so requests spread across cores

    cluster runs several worker processes on a shared listening socket so connections are distributed across cores. A single request still runs within one worker's event loop; cluster does not parallelize one request or multithread the loop.

    Read the full bite: Purpose of the Node.js cluster module

  27. Question 27 of 30

    Why can't a server send a chat message to a client over plain HTTP without the client asking first?

    Show the answer

    Answer: a · HTTP is request-driven; the server has no way to initiate communication or keep a persistent connection open to push data.

    HTTP's stateless model requires client initiation. The server cannot send unsolicited data. WebSocket solves this with a persistent, bidirectional tunnel. HTTP does support binary data and multiple requests per connection. The fundamental issue is that HTTP is pull-based, not push-based.

    Read the full bite: HTTP request-response versus WebSocket connections?

  28. Question 28 of 30

    In a multiplayer game, when a player moves their character, which Socket.IO method should the server use to notify other players of the movement?

    Show the answer

    Answer: a · socket.broadcast.emit(), so all players except the mover see the new position.

    The moving player already knows their own position. broadcast.emit() sends the update to everyone else without redundantly notifying the mover. io.emit() would broadcast to unrelated game lobbies. Looping socket.emit() is inefficient compared to a single broadcast.

    Read the full bite: Socket.IO emit methods: socket, io, broadcast differences?

  29. Question 29 of 30

    Why can't you initialize Socket.IO directly on the Express app object and use app.listen()?

    Show the answer

    Answer: c · Socket.IO needs the raw HTTP server object to upgrade connections to WebSocket, which app.listen() hides from you.

    Socket.IO requires access to the HTTP server to intercept and upgrade WebSocket connections. app.listen() returns a server, but Socket.IO needs that server as a parameter to io(server). Wrapping Express with http.createServer(app) explicitly gives Socket.IO access. Express does support WebSockets via the HTTP layer. Socket.IO can run on both HTTP and HTTPS.

    Read the full bite: How to add Socket.IO to an Express application?

  30. Question 30 of 30

    Why is hardcoding an API key in your source code and committing it to a public GitHub repo dangerous?

    Show the answer

    Answer: c · The API key can be found by inspecting the git history, and anyone with it can access your API quota or services.

    Once a secret is in git history, it is permanently discoverable even if deleted from the current version. Bots scan public repos for leaked credentials. GitHub doesn't automatically disable keys; you must manually rotate them. Keys in source code are equally dangerous whether in README or code. All environments, including dev, should use external configuration.

    Read the full bite: Environment configuration and secrets management in Node.js?

Could you explain these out loud?

That is what an interview actually tests. Tezvyn gives you questions like these with what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon