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
ECONNREFUSED when using node with nano and couchdb
919 Views Asked by MorningDew At
3
There are 3 best solutions below
0

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:
- Use
127.0.0.1
instead oflocalhost
in your URLs. - 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. - Revert to Nodev16 which preferred IPv4 addresses in its dns lookup.
- Make CouchDB bind to an IPv6 address by changing
bind_address = ::1
in couchdb.ini. You can then docurl 'http://USER:PASS@[::1]:5984/
.
See
https://github.com/apache/couchdb-nano/issues/313#issuecomment-1321760360
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 tonode changetoyourapp.js DEBUG=*
I faced yesterday same issue with nodejitsu/iriscouch. Issue disappeared after some restarts.