1

I want to connect my nodejs application to arangodb. I am using arangojs for this. My connection code looks like

new Database({
  url: `${DB_URL}:${DB_PORT}`,
  auth: {
    username: DB_USERNAME,
    password: DB_PASSWORD
  }
})
Error: connect EINVAL 0.0.33.81:80 - Local (0.0.0.0:0)
nodeserver_1  |     at internalConnect (node:net:905:16)
nodeserver_1  |     at defaultTriggerAsyncIdScope (node:internal/async_hooks:431:18)
nodeserver_1  |     at GetAddrInfoReqWrap.emitLookup [as callback] (node:net:1051:9)
nodeserver_1  |     at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:8) {
nodeserver_1  |   errno: -22,
nodeserver_1  |   code: 'EINVAL',
nodeserver_1  |   syscall: 'connect',
nodeserver_1  |   address: '0.0.33.81',
nodeserver_1  |   port: 80,

while DB_URL=db DB_PORT=8529

my docker-compose.yml looks like this:

version: '3.9'
services:
  db:
    image: arangodb:latest
    environment:
      ARANGO_ROOT_PASSWORD: ${DB_PASSWORD:-root}
    ports:
      - ${DB_PORT:-8529}:8529
    volumes:
      - arangodb_data_container:/var/lib/arangodb3
      - arangodb_apps_data_container:/var/lib/arangodb3-apps
    network_mode: bridge
  nodeserver:
    build:
      context: .
    depends_on:
      - db
    environment:
      DB_PORT: ${DB_PORT}
      DB_NAME: ${DB_NAME}
      DB_USERNAME: ${DB_USERNAME}
      DB_PASSWORD: ${DB_PASSWORD}
      DB_URL: ${DB_URL}
    restart: unless-stopped
    network_mode: bridge
volumes:
  arangodb_data_container:
  arangodb_apps_data_container:

Any idea what I did wrong?

Edit: I checked the containers IP address and it's not as I expected:

$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' 4059b252e72e
172.17.0.2

Edit2: I misinterpreted the error. The cause is the following code:

let db = new Database({
  url: `${DB_URL}:${DB_PORT}`,
  auth: {
    username: DB_USERNAME,
    password: DB_PASSWORD,
}
db = db.database(DB_NAME)
const databaseExists = await DB.database.exists() // here the error gets thrown
pgalle
  • 216
  • 3
  • 13

0 Answers0