APIs with Express · Chapter 29 of 29

The Express interview round

By the end of this chapter you can say what an Express app will do without running it, and find, explain and fix real bugs. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: The interview
  • 6 tasks
  • Express
  • In the all labs plan

The first 2 chapters of APIs with Express are free. This one comes with the all labs plan.

Why you need this

This is the round that proves the course. Dev turns his laptop around: four small Express apps, three bugs from Tapri's own history, and no terminal. "For the apps, tell me what runs, in order, and what the client gets. For the bugs, tell me what the user saw, why, and the smallest fix."

For twenty-eight chapters a terminal and a Check button caught every slip. Here you have neither, and a guess shows at once: a log line in the wrong place, a 404 instead of a 200. What gets you through is a method, and the rules behind it, said out loud.

What you build: 6 tasks

Each task has tests. You write the code in the lab's editor and press Check.

  1. Task 1 · interview question

    Interview: orderPrediction, the order middleware and routes run in

    Read orderApp and fill in orderPrediction without changing the app (the check runs its own copy of it). For each of the three requests, GET /menu/chai, GET /menu and POST /menu/chai, give logs, every value the app passes to log for that request, in the order it logs them, and status, the status code the client gets, as a number.

    Strings must be exactly what the app logs, with the values filled in (a template string becomes its text).

  2. Task 2 · interview question

    Interview: errorPrediction, the walk after next(err)

    Read errorApp and fill in errorPrediction for GET /order without changing the app: logs, every value it passes to log, in order, including anything logged after the response has gone out, and status, the status code the client gets, as a number.

  3. Task 3 · interview question

    Interview: doubleSendPrediction, then fix the order that is saved anyway

    Read doubleSendApp and fill in doubleSendPrediction for GET /bill without changing the app: logs, every value it passes to log, in order; status, the status code the client gets, as a number; and body, the JSON body the client gets, as a value.

    Then fix createOrdersApp. POST /orders without an item answers 400 with { error: 'item is required' } and saves nothing. POST /orders { item: 'masala-chai', qty: 2 } answers 201 with { id: 1, item: 'masala-chai', qty: 2 }, and { item: 'bun-maska' } gets { id: 2, item: 'bun-maska', qty: 1 }. GET /orders then lists exactly those two orders.

  4. Task 4 · interview question

    Interview: useVsAllPrediction, app.use or app.all

    Read useVsAllApp and fill in useVsAllPrediction without changing the app: for each of GET /admin, POST /admin/stock/milk and DELETE /administrator, the list of every value the app passes to log, in order (an empty list if it logs nothing).

  5. Task 5 · interview question

    Interview: createMenuApp, the async error that never arrives

    Fix createMenuApp({ loadMenu }). loadMenu returns a promise. GET /menu answers 200 with the menu when it resolves, and when it rejects the error reaches the app's error handler, which answers 500 with { error: 'Menu unavailable' }.

    Today a rejection reaches nobody: under the check the request never gets an answer, and the check gives up after 1 second.

  6. Task 6 · interview question

    Interview: corsWithCredentials, a named origin instead of a wildcard

    Fix corsWithCredentials(allowed). For a request whose Origin is in allowed (https://bluetokai.example), it sends Access-Control-Allow-Origin set to that origin and Access-Control-Allow-Credentials: true. For any other origin (https://evil.example, https://app.tapri.in.evil.example) or no Origin at all, it sends neither header.

    Every response's Vary header includes Origin, and every request still goes on to the route (200).

What you will learn

  • Tracing an app on paper: four questions for every entry in the list.
  • The rules, gathered: each one with the chapter that taught it.
  • Reading a bug report: what the client saw, what the server saw, and why.

More in The interview

Build The Express interview round yourself

Partner cafés want Tapri’s menu online by Friday: you build its API. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.

The first 2 chapters of APIs with Express are free. This one comes with the all labs plan.