Dredd "Error: connect ECONNREFUSED" to the API in CI
Dredd tried to connect to the API endpoint you passed and the host refused the connection, so nothing is listening there yet. In CI this means Dredd ran before the API was up, or the URL is wrong.
What this error means
Dredd errors every transaction with "Error: connect ECONNREFUSED 127.0.0.1:3000" and reports the API as unreachable.
dredd
error: Error connecting to server under test!
Error: connect ECONNREFUSED 127.0.0.1:3000Common causes
The API was not started or is still booting
Dredd ran before the service began listening, so the connection is refused for every transaction.
The endpoint URL host or port is wrong
The URL passed to Dredd targets a port the app does not bind, or the wrong host for a service container.
How to fix it
Start and wait for the API before Dredd
- Start the API in the background (or as a service container).
- Poll its health endpoint until it responds.
- Run Dredd against the confirmed-ready URL.
.github/workflows/ci.yml
- run: npm start &
- run: |
for i in $(seq 1 30); do curl -sf http://localhost:3000/health && break; sleep 2; done
- run: dredd apiary.apib http://localhost:3000Let Dredd start the server for you
Use the --server option so Dredd launches the app and waits before testing.
Terminal
dredd apiary.apib http://localhost:3000 \
--server "npm start" --server-wait 10How to prevent it
- Gate Dredd on a readiness check, or use
--serverwith a wait. - Confirm the endpoint host and port match how the API is exposed.
- Fail the wait step clearly if the API never comes up.
Related guides
Dredd "fail: statusCode: expected 200" in CIFix Dredd "fail: GET ... statusCode: expected 200 but got 500" in CI - the live API response does not match t…
schemathesis "Schemathesis found N failures" (server error) in CIFix "Schemathesis found N failures" in CI - schemathesis generated requests from your OpenAPI schema and the…
Newman "ECONNREFUSED" because the API is not up yet in CIFix Newman "ECONNREFUSED" in CI - the request could not connect because the API under test was not listening…