Node & Express Questions with Answers

10 practice questions on Node & Express (React & Web) with answers and step-by-step solutions. Try 10 samples below, then practise all 10 free in the AptiNest app.

Sample questions

Question 1Easy

What does npm install express --save (or the default install) record in package.json?

  1. The full source code of express
  2. The user password
  3. Only the Node version
  4. The dependency name and version range

Answer: D. The dependency name and version range

Explanation

package.json lists dependencies; node_modules holds the downloaded code.

Step-by-step solution

  1. npm installs the package.
  2. package.json records the range.

Why the other options are wrong

  • A. Code goes in node_modules.
  • B. package.json holds no secrets by design.
  • C. Dependencies are listed separately.

Question 2Easy

In Express, what does app.use(express.json()) do?

  1. Parses JSON bodies into req.body
  2. Sends JSON responses automatically
  3. Starts the server listening on a port
  4. Validates JSON schemas

Answer: A. Parses JSON bodies into req.body

Explanation

The middleware reads the body, parses JSON and stores the object on req.body.

Step-by-step solution

  1. Middleware runs before routes.
  2. It fills req.body.

Why the other options are wrong

  • B. res.json does that.
  • C. app.listen does that.
  • D. It only parses the body.

Question 3Easy

What is middleware in Express?

  1. A function taking req, res and next that runs per request
  2. A database driver
  3. A template engine
  4. A package manager

Answer: A. A function taking req, res and next that runs per request

Explanation

Middleware functions can modify the request or response, end it, or call next() to pass control on.

Step-by-step solution

  1. Receives req, res, next.
  2. Calls next() to continue.

Why the other options are wrong

  • B. Middleware is not a driver.
  • C. Template engines render views.
  • D. npm manages packages.

Question 4Medium

What does process.env.PORT commonly hold in a Node app?

  1. A global array of all open ports
  2. An environment variable, such as the listening port
  3. The hostname of the database
  4. A built-in constant of Node

Answer: B. An environment variable, such as the listening port

Explanation

Configuration such as ports and secrets is read from environment variables so it can differ per deployment.

Step-by-step solution

  1. process.env exposes env vars.
  2. Use PORT for deployment flexibility.

Why the other options are wrong

  • A. It is an environment variable.
  • C. Only if configured; PORT is the listening port.
  • D. Environment values are set by the system.

Question 5Medium

An Express middleware neither sends a response nor calls next(). What happens to the request?

  1. Express automatically calls the next middleware
  2. It hangs until it times out
  3. Express sends a 200 empty response
  4. The server crashes immediately

Answer: B. It hangs until it times out

Explanation

The chain only advances when next() is called, otherwise the client waits.

Step-by-step solution

  1. No response.
  2. No next().
  3. Client times out.

Why the other options are wrong

  • A. Express waits for next().
  • C. There is no automatic reply.
  • D. The request just stalls.

Question 6Medium

What is the main reason Node.js can handle many concurrent connections with one thread?

  1. It spawns a new OS thread for every request
  2. Non-blocking I/O with an event loop
  3. It compiles JavaScript to run in parallel on all cores automatically
  4. It forbids network calls

Answer: B. Non-blocking I/O with an event loop

Explanation

I/O operations are handed off and their callbacks run on the event loop when ready, so the thread is not blocked waiting.

Step-by-step solution

  1. I/O is delegated.
  2. Event loop runs callbacks.

Why the other options are wrong

  • A. Node uses an event loop with a small thread pool.
  • C. A single process runs JS on one thread.
  • D. Network calls are central to Node.

Question 7Medium

Which Express response correctly returns JSON with status 201?

  1. res.send(201).json({ ok: true })
  2. res.json(201, { ok: true })
  3. res.sendStatus({ ok: true })
  4. res.status(201).json({ ok: true })

Answer: D. res.status(201).json({ ok: true })

Explanation

status() sets the code and returns the response so json() can follow.

Step-by-step solution

  1. Set status first.
  2. Chain json().

Why the other options are wrong

  • A. send(201) sends a body; chaining json afterwards fails.
  • B. The numeric-status overload is removed or deprecated.
  • C. sendStatus takes a status code.

Question 8Medium

Which route reads the id from a URL like /users/42 in Express?

  1. app.get("/users", (req, res) => res.send(req.body.id))
  2. app.get("/users/id", (req, res) => res.send(req.id))
  3. app.get("/users?", (req, res) => res.send(req.query))
  4. app.get("/users/:id", (req, res) => res.send(req.params.id))

Answer: D. app.get("/users/:id", (req, res) => res.send(req.params.id))

Explanation

A :id segment becomes req.params.id, a string "42".

Step-by-step solution

  1. :id marks a route parameter.
  2. Read it from req.params.

Why the other options are wrong

  • A. req.body is for request bodies.
  • B. There is no req.id.
  • C. The path pattern does not capture 42.

Question 9Hard

In Express, where must a global error-handling middleware be placed, and what is its signature?

  1. Last, with four parameters (err, req, res, next)
  2. Before all routes, with two parameters
  3. Anywhere, with three parameters
  4. Inside each route only

Answer: A. Last, with four parameters (err, req, res, next)

Explanation

Express identifies error handlers by their four arguments and runs them for errors passed via next(err).

Step-by-step solution

  1. Four params marks an error handler.
  2. Register it last.

Why the other options are wrong

  • B. It would not catch route errors.
  • C. The four-parameter form marks error handlers.
  • D. It is registered once on the app.

Question 10Hard

A Node API runs a heavy CPU loop inside a request handler. What is the effect on other requests?

  1. Nothing, Node runs each handler in its own thread
  2. Only requests to the same route are delayed
  3. They wait, because the one JS thread is blocked
  4. The loop is automatically moved to the GPU

Answer: C. They wait, because the one JS thread is blocked

Explanation

CPU-bound work blocks the event loop; offload it to worker threads or another process.

Step-by-step solution

  1. One thread runs JS.
  2. The loop blocks it.
  3. Other requests wait.

Why the other options are wrong

  • A. JS code runs on one thread.
  • B. All requests share the same thread.
  • D. Node does no such thing.

Practise all 10 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all React & Web topics · All topics