'how can i connect code to my local cockroachdb cluster using NodeJs?

According to this tutorial, I created a local cockroachdb cluster with three nodes in the docker:

https://www.cockroachlabs.com/docs/v21.2/start-a-local-cluster-in-docker-windows

Now i try connect to this by postgresSQL

const { Client } = require('pg')
const client = new Client('postgresql://root@roach1:26257?sslmode=disable')
client.connect()

I've create new DB user through console named his as "ncado" and set "root" as password Conection string create from this template:

https://www.cockroachlabs.com/docs/stable/connect-to-the-database.html

const { Client } = require('pg')
const client = new Client('postgresql://ncado:root@localhost:8080/messages.message?sslmode=verify-full&options=--cluster%3Droach1')
client.connect()

if i try change port to 26257, code throws error

node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: getaddrinfo ENOTFOUND roach1
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:72:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'roach1'
}

I've been testing my connection by this code:

app.post('/test', async (req,res)=>{
  const text = 'INSERT INTO messages.public.messag VALUES($1, $2,$3) RETURNING *'
  const values = [4, 'berserk',"HAI YAI FOOOORCES"]
  await client.query(text, values)
  res.send('done')

 
})

When i do request to that endpoint was starting endless "sending request"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source