New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error ECONNREFUSED when connecting to database #313
Comments
My variation on your test script works just fine: const nano = require("nano")(process.env.COUCH_URL);
const db = nano.db.use("mydb")
const main = async () => {
const i = await db.info()
console.log(i)
}
main() |
I had the same issue (curl and other ways of connecting with CouchDB worked fine, nano failed with ECONNREFUSED). I was using Node 18. Based on this SO answer I downgraded to Node 16 and it worked. |
That's interesting. I'll try with node18
…On Sat, 19 Nov 2022, 00:34 Adriano Ferrari, ***@***.***> wrote:
I had the same issue (curl and other ways of connecting with CouchDB
worked fine, nano failed with ECONNREFUSED).
I was using Node 18. Based on this SO answer
<https://stackoverflow.com/a/73146534/43769> I downgraded to Node 16 and
it worked.
—
Reply to this email directly, view it on GitHub
<#313 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFKMRJUUWRHS6DYSZ4E2DLWJAOAVANCNFSM6AAAAAARXMG7ZI>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Just tried with 18.12.1 and it worked fine when connecting to a remote CouchDB API over https but failed when connecting to a local CouchDB over http. I'm going to investigate that further. As @AdrianoFerrari notes, changing to Node 16 fixes the problem. I've confirmed the same happens with just plain old axios e.g axios.request({url: 'http://localhost:5984/mydb', method: 'get'}) so it's nothing special about Nano per se. |
It appears to be to do with the way that "localhost" is interpreted. In Node 16, Note that in a default Mac
So it appears that in Node 18+, it's preferring the IPv6 option. i.e. if you change your code to const nano = require("nano")(`http://${user}:${pass}@127.0.0.1:5984`); then it'll work. |
So this is down to how Node.js resolves DNS hostnames. In Node v16, calling the built-in function dns.lookup returns Given a URL with a
CouchDB doesn't listen on IPv6 addresses, as by default it's bound to There are a number of solutions:
|
Expected Behavior
Couchdb nano should connect to database.
Current Behavior
My couchdb server is running at localhost:5984. curl requests from terminal work fine.
In a next.js api endpoint:
when I run this I get:
Possible Solution
Steps to Reproduce (for bugs)
npx create-next-app@latest
npm install nano
npm run dev
Context
Your Environment
The text was updated successfully, but these errors were encountered: