NodeJS: connect ECONNREFUSED error

Tuesday, September 20, 2022

I've been writing integration tests for my NodeJS app using supertest and mongodb-memory-server and for one of my test cases, I was encountering the error connect ECONNREFUSED error whenever I ran the test suite.

The solution is so simple you would not believe it.

Check that the url passed to supertest has a / prefix 🤦🏽‍♀️.

In my case, it was'api/auth/login') instead of'/api/auth/login').

Powered By Swish