🌍 ExpressJS · flashcards

ExpressJS Testing and Debugging in ExpressJS Flashcards

50 question-and-answer cards covering Testing and Debugging in ExpressJS as it is examined in ExpressJS. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.

50Cards in deck
24Free preview
7Syllabus topics
~210Chars per answer
FreePrice

24 sample cards from the Testing and Debugging in ExpressJS deck

Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.

  1. How would you stub a model method (e.g. User.find) so an Express handler test does not hit the real database?

    Use sinon.stub(User,'find').resolves([{id:1}]) (or .returns/.rejects) so the handler receives the fake result. Restore it afterward with .restore() (often in afterEach) to avoid leaking the stub into other tests.

  2. What library allows you to intercept and mock outgoing HTTP requests to external APIs in Node tests?

    nock. It intercepts HTTP(S) requests at the network layer, letting you define expected requests and canned responses, so tests of code that calls external APIs run without real network traffic.

  3. Why should you always restore stubs/spies after each test, and what Sinon feature simplifies this?

    Unrestored stubs persist and corrupt later tests (leaking fakes, false passes/failures). Use a sinon.createSandbox() (or sinon.sandbox) and call sandbox.restore() in afterEach to reset all fakes in one call.

  4. What is the Debug module and why use it instead of console.log in Express apps?

    debug is a small utility that provides namespaced, conditional logging. Unlike console.log, its output is off by default and enabled selectively via the DEBUG environment variable, so you get targeted diagnostics without cluttering production output or editing code.

  5. How do you create and use a namespaced debugger with the debug module?

    const debug = require('debug')('app:server'); then call debug('listening on %d', port). 'app:server' is the namespace; the message only prints when that namespace is enabled.

  6. How do you enable debug output for a specific namespace when running an Express app?

    Set the DEBUG environment variable, e.g. DEBUG=app:server node app.js. Use DEBUG=app:* to enable all namespaces under 'app', or DEBUG=* for everything.

  7. How do you enable multiple debug namespaces but exclude one?

    Comma-separate namespaces and prefix an exclusion with '-', e.g. DEBUG=app:*,-app:db enables all app namespaces except app:db. Wildcards (*) match any characters.

  8. What formatting placeholders does the debug module support, and give two examples.

    printf-style formatters: %s (string), %d (number), %j (JSON), %o/%O (object inspection), %% (literal percent). Example: debug('user %s id %d', name, id).

  9. In the Express generator's default app, which debug namespace is commonly used and where?

    The generated bin/www uses require('debug')('<appname>:server') to log server startup and errors (e.g. the listening event and error handler), enabled via DEBUG=<appname>:*.

  10. What is the Node.js Inspector, and how do you start an Express app with it enabled?

    The Node.js Inspector is a built-in debugger exposing the V8 Inspector Protocol over WebSocket, usable with Chrome DevTools or VS Code. Start it with node --inspect app.js (or node --inspect-brk app.js to break before the first line).

  11. What is the difference between --inspect and --inspect-brk?

    --inspect starts the inspector and runs the program immediately (you must have set breakpoints or attach quickly). --inspect-brk starts the inspector and pauses on the first line of code, letting you attach a debugger before anything executes.

  12. What default host and port does node --inspect use, and why is binding to 0.0.0.0 discouraged?

    It listens on 127.0.0.1:9229 by default. Binding to a public interface (--inspect=0.0.0.0:9229) is a security risk because the inspector allows arbitrary code execution; anyone who can reach the port can control the process.

  13. How do you connect Chrome DevTools to a running Node inspector session?

    Open chrome://inspect in Chrome and click the target under 'Remote Target', or navigate to the devtools:// URL printed to the console when the inspector starts. You can also attach VS Code's Node debugger.

  14. What is a breakpoint, and how can you set one directly in Node source code without a GUI?

    A breakpoint pauses execution at a specific line so you can inspect state. You can hardcode one with the debugger; statement, which halts execution there whenever an inspector is attached.

  15. Which Chai assertion checks that a function throws an error, and how is it written?

    expect(fn).to.throw() (optionally expect(fn).to.throw(TypeError, /message/)). Pass the function itself (not its invocation) so Chai can call it and catch the thrown error.

  16. How do you assert on the shape of a JSON array response body (e.g. length and element property) with Chai?

    expect(res.body).to.be.an('array').with.lengthOf(3); and expect(res.body[0]).to.have.property('id'). Chained language assertions verify type, length, and member properties.

  17. What npm script convention runs Mocha tests, and how is Mocha typically invoked?

    Add "test": "mocha" (optionally with a glob like "mocha './test/**/*.spec.js'") to package.json scripts, then run npm test. Mocha by default looks in the ./test directory.

  18. How do you test that an Express route responds with the correct Content-Type header using Supertest?

    request(app).get('/api').expect('Content-Type', /json/).expect(200). Passing a header name and a regex/string to .expect() asserts on that response header.

  19. When mocking a database in a route integration test, why is dependency injection preferable to stubbing globally?

    Dependency injection (passing the db/service into the handler or module) makes the dependency explicit and lets you supply a fake in tests without patching global module internals. It reduces coupling, avoids fragile stub-restore bookkeeping, and makes tests more reliable.

  20. What is the purpose of proxyquire (or rewire) in Express testing?

    proxyquire lets you require a module while overriding its own require() calls, so you can inject mock versions of that module's dependencies. It is used when a dependency is required internally and cannot easily be stubbed or injected.

  21. How can you test error-handling middleware end-to-end with Supertest?

    Trigger a route that calls next(err) (or throws), then assert the response reflects the error handler's output, e.g. request(app).get('/boom').expect(500).expect(res => expect(res.body.error).to.exist). This verifies the error middleware is wired correctly.

  22. What Node.js CLI command opens the built-in command-line debugger (not DevTools), and name two of its stepping commands.

    node inspect app.js opens the built-in CLI debugger. Stepping commands include cont (c) to continue, next (n) to step over, step (s) to step into, out (o) to step out, and repl to inspect variables.

  23. Why can leaving app.listen() calls in modules under test cause problems, and what is the fix?

    Calling app.listen() at import time binds a port; multiple test files can collide (EADDRINUSE) or leave open handles that prevent Mocha from exiting. Fix: export the app and only call listen() in a separate entry point (e.g. bin/www) or let Supertest manage the ephemeral port.

  24. Compare the debug module and the Node.js Inspector as diagnostic tools for Express.

    The debug module gives lightweight, always-in-code, namespace-filtered log output controlled by DEBUG at runtime — good for tracing flow in dev and production. The Node.js Inspector is an interactive debugger with breakpoints, step execution, and live variable inspection via DevTools/VS Code — good for deep, stateful investigation during development.

What this deck covers

The Testing and Debugging in ExpressJS deck follows the ExpressJS Testing and Debugging in ExpressJS syllabus — 3 chapters and 7 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 16.7 cards per chapter.

Answers are written to be recallable, not just readable — averaging about 210 characters, which is long enough to carry the reasoning and short enough to say out loud.

A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.

Testing and Debugging in ExpressJS flashcards FAQ

How many Testing and Debugging in ExpressJS flashcards are in this ExpressJS deck?

50 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.

Are these ExpressJS flashcards free?

Yes. The preview here is free to read with no signup, and the full 50-card deck is free inside the Examius app.

What do the Testing and Debugging in ExpressJS cards cover?

They follow the ExpressJS Testing and Debugging in ExpressJS syllabus — 3 chapters and 7 topics — so the questions track what is actually examinable.

How should I use these flashcards?

Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.