NodeJS: connect ECONNREFUSED 127.0.0.1:80 error

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 127.0.0.1:80 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 request.post('api/auth/login') instead of request.post('/api/auth/login').

Powered By Swish