Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

NestJS Module 2

Controllers, routing and versioning interview questions

Interview questions on controllers, routing and versioning: warm-ups, then what each harder question tests and how a good answer starts.

11 questions: 3 warm-ups and 8 with model answers · Levels: Fresher to staff

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher to mid

    Which status code does a NestJS handler send by default, and how do you change it?

    Answered in the lesson Controllers and route handlers

  2. Fresher to mid

    Why can @Get(':id') declared before @Get('me') break GET /users/me on the Express adapter?

    Answered in the lesson Route order, paths and conflict checks

  3. Fresher to mid

    What does VERSION_NEUTRAL do in a NestJS app that uses versioning?

    Answered in the lesson Versioning, global prefixes and the router module

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Mid to senior

    A NestJS handler injects @Res() to set a response header, then returns an object. In production these requests time out, though the handler finishes in milliseconds. Explain what happened, and give two ways to fix it.

    What it tests
    Understanding library-specific mode, what Nest stops doing when @Res() is injected, and choosing the fix that keeps Nest's own response handling.
    First step
    Notice that the handler finished but nothing was sent. Injecting @Res() switches the handler to library-specific mode: Nest ignores its return value and expects the handler to call res.json() or res.send() itself. Nobody did, so each client waited until a timeout.
    Follow-ups

    From the lesson Controllers and route handlers

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; nothing renews unless you choose to. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  2. Fresher to senior

    A paginated endpoint reads @Query('limit') limit: number and fetches limit + 1 rows to know whether a next page exists. With ?limit=10 it asks the database for 101 rows. Explain the bug, and fix it so that the codebase cannot repeat it.

    What it tests
    Knowing that query values arrive as strings whatever their TypeScript type, and moving conversion and validation into one place that every handler uses.
    First step
    Check the value at run time, not its type annotation. Query values arrive as strings, so limit is '10', and '10' + 1 joins text into '101'. The annotation number is erased at compile time and converts nothing.
    Follow-ups

    From the lesson Controllers and route handlers

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  3. Mid to senior

    You are switching on Nest 12's routeConflictPolicy for a large app on the Express adapter. Which settings do you choose for development, CI and production, and how do you make sure a lost route fails the build?

    What it tests
    Telling duplicates from overlap, knowing what each severity does at start-up, and pairing the checks with tests that prove each route is reachable.
    First step
    Separate the two kinds of conflict. A duplicate means two identical routes, so one handler never runs. A shadow means two patterns can match the same request, which may be deliberate. Then decide, for each kind and each environment, whether off, warn or error fits.
    Follow-ups

    From the lesson Route order, paths and conflict checks

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  4. Senior to staff

    A team sets routeResolutionStrategy to 'specificity' together with routeConflictPolicy { shadow: 'error' } in CI. Predict what happens to a controller that declares 'me' before ':id', and to one that declares ':id' first, and explain the rule behind your prediction.

    What it tests
    Reasoning about what each option does and how Nest combines them, instead of assuming that two safety options add up to more safety.
    First step
    Start from each option alone. Specificity changes the order Nest registers routes in. The shadow check compares pairs of routes that can match the same request. Then ask which pairs the check still reports once the routes have been sorted.
    Follow-ups

    From the lesson Route order, paths and conflict checks

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  5. Mid to senior

    You are upgrading a Nest 10 app on Express 4 to Nest 12. Its routes include 'files/*', 'orders/:id?' and a path with regular-expression characters. What changes, what stops working, and how do you make the migration safe?

    What it tests
    Knowing path-to-regexp 8's syntax and how Nest 12 treats old patterns, and planning a migration that finds every pattern before production does.
    First step
    List every path string in the app, in route decorators, middleware forRoutes() calls and global prefix exclusions, and check each one against the path syntax of Express 5, which Nest 12 uses for all three. Then decide how you will find the patterns the list missed before production does.
    Follow-ups

    From the lesson Route order, paths and conflict checks

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  6. Mid to senior

    Older mobile app versions never send a version header. Right after a small configuration change to a NestJS app that uses header versioning, those apps start getting 404 from endpoints that worked before. Explain how a configuration change can cause this, how you would find it, and how you fix it without breaking newer clients.

    What it tests
    Knowing what each versioning option really does to controllers and requests, reproducing the failure, and choosing declarations that serve clients without a version on purpose.
    First step
    Reproduce one request without the header against the configuration before and after the change, and compare which controllers answer. Then list, for each controller, which versions it declares, and what the versioning options give the controllers that declare none.
    Follow-ups

    From the lesson Versioning, global prefixes and the router module

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  7. Mid to senior

    A monitoring check of GET /health against a NestJS API on Express gets a 404 whose body the monitor cannot parse, although every other error of the API is JSON. The app calls setGlobalPrefix('api'). Explain what answered, and how you would make every response of the API JSON.

    What it tests
    Knowing where Nest's not-found handling lives relative to a global prefix, how adapters differ, and which fix suits a public API.
    First step
    Find out which code produced the response. A path outside the prefix may never reach any of Nest's handlers, so compare a request inside the prefix that matches no route with one outside it, and look at the content type of each answer.
    Follow-ups

    From the lesson Versioning, global prefixes and the router module

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  8. Senior to staff

    Design how a public NestJS API introduces version 2 of its menu endpoint, keeps existing clients working, and retires version 1. Cover the versioning type, the controller declarations, and how clients learn about the retirement.

    What it tests
    Choosing a versioning type for the clients, declaring versions so that old and new clients both work, and retiring a version with standard signals and evidence instead of a guess.
    First step
    Start from the clients: who calls the API, whether they can send headers, and whether URLs are cached or shared. That decides between URI and header versioning. Then decide what a request without any version should get, before writing a single declaration.
    Follow-ups

    From the lesson Versioning, global prefixes and the router module

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes

All NestJS interview questions · The NestJS track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.