Supertest is the standard library for sending HTTP-like requests directly to an Express app object in tests, without binding to a real network port. This lesson covers its API in depth.
How Supertest Works
request(app) wraps your Express app and returns a chainable object mirroring the HTTP methods, .get(), .post(), .put(), .delete(). Each call returns a promise resolving to a response object with status, body, headers, and more.
Because it operates directly on the app object rather than a live server, tests run fast and don't require managing port conflicts or actually starting the process.
Multi-step test flows can chain several requests to verify a full resource lifecycle.
Pro Tip
Pass the plain exported app object into request(), never a server returned by app.listen(), supertest manages its own ephemeral port internally and doesn't need (or want) a real listener.
You now know how to test Express APIs with supertest. Next, learn techniques for debugging Express apps in the Debugging lesson.