MorningDew
MorningDew

Reputation: 503

ECONNREFUSED when using node with nano and couchdb

I was using nodejs + nano + couchdb for my application successfully up until today. For some reason all of a sudden I'm getting ECONNREFUSED when I try to run my application. If I try to query the database using the web browser or using a different application (java application) it works fine. I'm uncertain why just in this scenario it stopped working. I've been researching for the past 2 days and can't find any help. I believe this might have something to do with too many open connections, but that's a little bit out of my realm of knowledge. Can anyone provide me with any insight on debugging this issue or any direction I could go in? I should mention this couchdb lives on iriscouch

Upvotes: 1

Views: 976

Answers (3)

Glynn Bird
Glynn Bird

Reputation: 5637

This is down to Node v18 now preferring an IPv6 address over and IPv4 address if two exist for the same hostname.

i.e. if your /etc/hosts contains entries like this:

127.0.0.1          localhost
::1                localhost

Node v16 will say that "localhost" resolves to 127.0.0.1 where Node v18 will say "localhost" resolves to ::1, the IPv6 equivalent. As CouchDB doesn't listen on an IPv6 port by default, then a connection to ::1 will be refused.

Solutions:

  1. Use 127.0.0.1 instead of localhost in your URLs.
  2. Use a domain name that resolves unambiguously to an IPv4 address e.g. 127.0.0.1 my.pretend.host in your /etc/hosts file.
  3. Revert to Nodev16 which preferred IPv4 addresses in its dns lookup.
  4. Make CouchDB bind to an IPv6 address by changing bind_address = ::1 in couchdb.ini. You can then do curl 'http://USER:PASS@[::1]:5984/.

See

https://github.com/apache/couchdb-nano/issues/313#issuecomment-1321760360

Upvotes: 3

Fred Guth
Fred Guth

Reputation: 1667

Check the version of your node vs the expected node version of nano. It is possible that nano does not work with node > 16.

Upvotes: 1

Tim Marinin
Tim Marinin

Reputation: 358

Add more information about stack that you're using. But basically it's server machine doesn't want to allow connecting. Also try run your app with DEBUG=*, nano will log via console.log almost everything.

E.g. change in package.json start command to node changetoyourapp.js DEBUG=*

I faced yesterday same issue with nodejitsu/iriscouch. Issue disappeared after some restarts.

Upvotes: 2

Related Questions