Keploy logo
Node.js logo

Keploy as a Node.js testing framework

Keploy tests Node.js services by recording real HTTP requests and every downstream call they trigger, then replaying both as assertions. There are no nock interceptors to register, no jest.mock factories to maintain, and no in-memory database to seed before a test runs.

Generate Node.js tests free
keploy record -c "npm start"
18.4K+VS Code1.2M+300M+mocks created

What Keploy gives a Node.js team

Any Node service, unchanged

Keploy wraps your start script. Express, Fastify, NestJS, Koa, and Hapi all record identically, and TypeScript is irrelevant to capture because Keploy records the running process rather than your source.

  • Node 16 and above, CJS or ESM
  • No exported app object required
  • TypeScript needs no extra setup
  • Full middleware stack executes
The problem

Why Node.js integration tests slow teams down

The friction is rarely the assertions. It is everything around them — spinning up dependencies, keeping mocks honest, and repairing tests after every refactor.

Three ways to do it

Testing Node.js: by hand, with Jest + nock + supertest, or with Keploy

Every nock interceptor and module mock is a hand-written copy of a contract you do not own. Keploy records the real response, so re-recording refreshes all of them at once.

Select any row for the full comparison, with code.

Same coverage, three costs

What you write for Node.js vs what Keploy records

All three produce the same assertion. Only the third still passes after the next refactor without anyone editing it.

By hand2–4 hours
orders.manual.test.js
hand-written
// Hand-written: stubs, payloads, and assertions by hand.
const request = require('supertest');
const buildApp = require('../src/app');
 
const fakeRepo = {
get: async (id) => ({ id, amountMinor: 4200, state: 'NEW' }),
save: async (order) => order,
};
 
const fakePayments = {
charge: async () => ({ status: 'AUTHORIZED', id: 'ch_1' }),
};
 
describe('POST /orders/:id/confirm', () => {
it('confirms an authorized order', async () => {
const app = buildApp({ repo: fakeRepo, payments: fakePayments });
 
const res = await request(app)
.post('/orders/ord_1/confirm')
.send({ paymentToken: 'tok_123' });
 
expect(res.status).toBe(200);
expect(res.body.state).toBe('CONFIRMED');
expect(res.body.amountMinor).toBe(4200);
});
});

Two stub objects exist only for this file, and both hard-code a shape that nothing verifies against the real Mongo document or Stripe response.

Jest + nock + supertest1–2 hours
orders.jest.test.js
tool-assisted
// Jest + nock + supertest + mongodb-memory-server.
const nock = require('nock');
const request = require('supertest');
const { MongoMemoryServer } = require('mongodb-memory-server');
 
let mongo;
 
beforeAll(async () => {
mongo = await MongoMemoryServer.create();
await connect(mongo.getUri());
await seedOrders([{ _id: 'ord_1', amountMinor: 4200, state: 'NEW' }]);
});
 
afterAll(async () => {
await mongo.stop();
nock.cleanAll();
});
 
it('confirms an authorized order', async () => {
// A literal that will not change when Stripe does.
nock('https://api.payments.example.com')
.post('/v1/payment_intents/tok_123/confirm')
.reply(200, { status: 'AUTHORIZED' });
 
const res = await request(app)
.post('/orders/ord_1/confirm')
.send({ paymentToken: 'tok_123' });
 
expect(res.status).toBe(200);
expect(res.body.state).toBe('CONFIRMED');
});

Three libraries, a downloaded mongod binary, and a seed step — and the Stripe body is still a hand-typed literal nobody re-checks.

With Keploy~5 minutes
test-1.yaml
auto-generated
# Recorded with: keploy record -c 'npm start'
# Nobody wrote this file. Keploy captured it from a real request.
version: api.keploy.io/v1beta1
kind: Http
name: test-1
spec:
req:
method: POST
url: /orders/ord_1/confirm
body: '{"paymentToken":"tok_123"}'
resp:
status_code: 200
body:
id: "ord_1"
state: "CONFIRMED"
amountMinor: 4200
confirmedAt: "2026-09-02T11:04:18Z"
noise:
- body.confirmedAt
# No nock, no memory server, no seed step.
mocks:
- kind: Mongo
operation: "orders.findOne({ _id: 'ord_1' })"
- kind: Http
url: https://api.payments.example.com/v1/payment_intents/tok_123/confirm
status: 200

The Mongo document and the Stripe response are recorded from the real dependencies. Re-recording after an upstream change updates both automatically.

Times are estimates for authoring one endpoint’s coverage from scratch, not measurements.

Keploy vs the alternatives

Node.js testing tools, compared

The options a team on Node.js actually reaches for, and where each one genuinely wins. Select a row for the full comparison.

Best in classStrongPartialNot covered

Assessments reflect each tool’s documented behaviour, not benchmark measurements.

How it works

Record your Node.js app once, replay it forever

Keploy sits below your Node.js process at the network layer. It watches the calls your app already makes, then serves them back on replay so tests run with no dependencies attached.

Keploy records a GET call to /api/v1/orders/{id} on a Node.js service and captures the dependency calls it makes.

An example shape of a captured call. Your own endpoints and dependencies come from your real traffic, so nothing here has to be written by hand.
Mock coverage

What Keploy mocks for Node.js, with zero config

7 of the 8 dependencies a typical Node.js service talks to are stubbed from the recording itself — no mock classes, no fixture files, no containers in CI.

Quick start

Your first Node.js test suite in under five minutes

Every command below runs against your existing Node.js service. Nothing in your source tree changes.

  1. 1Install the Keploy CLI

    A standalone binary — not an npm package, so package.json and your lockfile stay untouched.

    curl -sSL https://keploy.io/install.sh | bash
  2. 2Record your service

    Hand Keploy the start script you already use. It runs the process and watches every socket it opens.

    keploy record -c "npm start"
  3. 3Exercise your routes

    curl, Postman, your frontend, or an existing smoke script. Each request becomes a test case with its mocks attached.

    curl -X POST localhost:3000/orders/ord_1/confirm -H 'Content-Type: application/json' -d '{"paymentToken":"tok_123"}'
  4. 4Replay in CI

    Replay serves recorded dependency responses, so no Mongo service or memory server is needed in the runner.

    keploy test -c "npm start" --delay 10

Ready to try it on your own Node.js service?

Ecosystem

Works with the rest of your Node.js stack

Keploy records at the network layer, so framework and driver choices inside your Node.js app do not change how it captures traffic.

  • Express logo

    Express

    Recorded through the HTTP server — middleware order is irrelevant.

  • NestJS logo

    NestJS

    Wrap nest start; providers and modules need no test doubles.

  • Fastify logo

    Fastify

    Same capture path as Express; plugins do not affect recording.

  • Prisma logo

    Prisma

    Queries are captured as the Postgres or MySQL protocol they emit.

  • Mongoose logo

    Mongoose

    Recorded as MongoDB wire traffic, not as model method calls.

  • TypeScript logo

    TypeScript

    Nothing to type. Keploy records the running process, not the source.

FAQ

Node.js testing with Keploy: common questions

Join our GlobalCommunity

Connect with developers worldwide. Follow updates, ask questions, share feedback, and ship faster with other Keploy builders.

1.2M+Installs
18.4K+GitHub
100K+Devs
300M+Mocks
1K+Contributors
#1OSS Trending
4.9★★★★★from 500+ reviews onG2GartnerVS CodeChrome
★★★★★

Best report of integration and API tests I've seen — which we don't get from RestAssured.

G2
★★★★★

Future of microservices testing. I don't write tests now!

G2 · 5/5
★★★★★

An amazing product that simplifies the automation.

Gartner · 4.0
XGitHubSlackYouTubeLinkedIn
Built by developers, for developers.Let's build the future, together.