Skip to content
tezvyn:

Node.js & Express

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

65 bites

Test yourself: Top 30 intermediate Node.js & Express interview questionsMultiple choice, with the correct answer and why it is correct on every question. Free, no sign-in.

Intermediate interview questions in Node.js & Express, page 2

intermediate1 min read

Middleware execution order and sharing data via req

Middleware runs top-down in registration order; each calls next(); attach data like req.user that later handlers read.

intermediate1 min read

Modularize routes with express.Router

Create a Router per resource in its own file, define routes on it, export it, and mount with app.use('/products', router).

intermediate1 min read

Idempotency: PUT vs POST in REST

Idempotent means repeated identical requests leave the same server state; PUT is idempotent, POST is not. Use PUT to overwrite a resource at a known URL.

intermediate1 min read

404 vs 500: missing resource vs server failure

A missing resource returns 404 Not Found (client asked for something absent); a database failure returns 500 Internal Server Error (server-side fault).

intermediate1 min read

Mongoose populate() for referenced documents

Populate() replaces stored ObjectIds with the referenced documents, needs a ref in the schema, called via .populate('author').

intermediate1 min read

Database migrations with the Sequelize CLI

Migrations are version-controlled scripts with up/down so teams apply identical schema changes; use sequelize-cli to generate, edit with addColumn, then db:migrate.

intermediate1 min read

Mongoose pre('save') hooks for password hashing

Pre('save') runs before persistence; use it to hash the password, guarding with isModified, calling next() or returning.

intermediate1 min read

Session-based versus token-based authentication

Sessions store server-side state with a cookie id, tokens carry self-contained claims with no server store, weigh revocation versus scalability, especially across services.

intermediate1 min read

Securing Express with Passport local strategy

Configure LocalStrategy with a verify callback, call passport.authenticate as route middleware, and set up serializeUser/deserializeUser for sessions.

intermediate1 min read

Propagating async errors to Express error handlers

Express does not auto-catch rejected promises, so catch and call next(err), or wrap handlers in an asyncHandler that forwards rejections; Express 5 awaits handlers automatically.

intermediate1 min read

Reusable schema validation middleware with Zod or Joi

Define a schema (email, password min 8, optional firstName), write a factory middleware that validates req.body, returns 400 with messages on failure, and assigns the parsed value on success.

intermediate1 min read

Custom Error classes and centralized handling

Custom Error subclasses carry a statusCode and flag, the central handler inspects instanceof or statusCode to set the HTTP code and JSON shape, defaulting unknown errors to 500.

intermediate1 min read

Operational versus programmer errors in Node.js

Operational errors are expected runtime conditions you handle and respond to; programmer errors are bugs that may corrupt state, so you log and gracefully restart.

intermediate1 min read

Integration testing a POST endpoint with Supertest

Pass the Express app to supertest, send a POST with a body, then assert status 201, the response shape, and the persisted side effect; also test validation failures.

intermediate1 min read

Mocking the database layer in Jest unit tests

A live DB makes tests slow, flaky, and order-dependent; use jest.mock on the model so methods return controlled fakes.

intermediate1 min read

Testing async Promise-returning code in Jest

Return or await the promise; use await expect(...).resolves/rejects, or await the value directly.

intermediate1 min read

Explaining and preventing CSRF in Express

CSRF abuses a victim's ambient cookies to forge state-changing requests; the server issues an unpredictable token tied to the session, embeds it in forms, and validates it…

intermediate1 min read

Preventing SQL injection with parameterized queries

The flaw is SQL injection; prevent it with parameterized queries/prepared statements (pg $1, mysql2 ?), never string concatenation, so input is data not code.

intermediate1 min read

Input validation versus output encoding

Validation checks input fits expected rules on entry; encoding makes data safe for a specific output context on exit. You need both; encoding is the real anti-XSS control.

intermediate1 min read

Auditing and fixing vulnerable npm dependencies

Run npm audit (or yarn audit) to list advisories, npm audit fix to patch within semver, bump majors deliberately, and lock versions; wire audits into CI.

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles