# Connection Error (NodejsClient 8.0)

**URL:** <https://discuss.elastic.co/t/connection-error-nodejsclient-8-0/298028>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [February 23, 2022, 12:10pm UTC](https://discuss.elastic.co/t/connection-error-nodejsclient-8-0/298028 "2022-02-23T12:10:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev\_test](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dev_test/32/79287_2.png) [@dev\_test](https://discuss.elastic.co/u/dev_test)\
**Post date:** [February 23, 2022, 12:10pm UTC](https://discuss.elastic.co/t/connection-error-nodejsclient-8-0/298028/1 "2022-02-23T12:10:00Z")

</div>

Hi,  
I am trying to connect to my Elasticsearch 8.0 cluster through a Javascript client 8.0 and I am having this error

```auto
ConnectionError: other side closed - Local: 172.31.0.1:60684, Remote: 172.31.0.4:9200
    at SniffingTransport.request (/home/ilsa/work/fayvo/nodeexpress/node_modules/@elastic/transport/lib/Transport.js:525:31)
    at async Client.SearchApi [as search] (/home/ilsa/work/fayvo/nodeexpress/node_modules/@elastic/elasticsearch/lib/api/api/search.js:65:12)
    at async data_aggregation (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:340:22)
    at async getAggregatedData (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:233:19)
    at async responseMapper (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:173:19)
    at async isFayvedMapper (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:159:24)
    at async get_results (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:95:27)
    at async exports.get_web (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:79:23)
    at async Object.exports.get_trends (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/api_caller.js:46:40)
    at async exports.get_trend (/home/ilsa/work/fayvo/nodeexpress/controllers/suggestionController.js:5:16) {
  meta: {
    body: undefined,
    statusCode: 0,
    headers: {},
    meta: {
      context: null,
      request: [Object],
      name: 'elasticsearch-js',
      connection: [Object],
      attempts: 3,
      aborted: false
    },
    warnings: [Getter]
  }
}

{
    "data": {
        "name": "ConnectionError",
        "meta": {
            "statusCode": 0,
            "headers": {},
            "meta": {
                "context": null,
                "request": {
                    "params": {
                        "method": "POST",
                        "path": "/_search",
                        "body": "{\"query\":{\"bool\":{\"must\":[{\"match_all\":{}}]}}}",,
                        "querystring": "",
                        "headers": {
                            "user-agent": "elastic-transport-js/8.0.2 (linux 5.13.0-30-generic-x64; Node.js v14.18.3)",
                            "x-elastic-client-meta": "es=8.0.0,js=14.18.3,t=8.0.2,hc=14.18.3",
                            "content-type": "application/vnd.elasticsearch+json; compatible-with=8",
                            "accept": "application/vnd.elasticsearch+json; compatible-with=8",
                            "content-length": "4485"
                        }
                    },
                    "options": {},
                    "id": 1
                },
                "name": "elasticsearch-js",
                "connection": {
                    "url": "http://172.31.0.4:9200/",
                    "id": "http://172.31.0.4:9200/",
                    "headers": {},
                    "status": "alive"
                },
                "attempts": 3,
                "aborted": false
            },
            "warnings": null
        }
    }
}

```

The client that i'm preparing to connect looks something like this

```auto

let url = new URL(ELASICSEARCH_HOST)
url['username'] = ELASICSEARCH_USER
url['password'] = ELASICSEARCH_PASS
const client = new Client({
    node: {
        url: url
    }
});

const client = new Client({
    node: {
        url: new URL(ELASICSEARCH_HOST),
        auth: {
            username: ELASICSEARCH_USER,
            password: ELASICSEARCH_PASS
        }
    }
});

```

I have mentioned two client definitions above (i have tried to make connection using both but no success)

can anyone please help me in making a connection to Elasticsearch 8.0 cluster

---

<div class="post-metadata">

**Author:** ![dev\_test](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dev_test/32/79287_2.png) [@dev\_test](https://discuss.elastic.co/u/dev_test)\
**Post date:** [February 23, 2022, 12:59pm UTC](https://discuss.elastic.co/t/connection-error-nodejsclient-8-0/298028/2 "2022-02-23T12:59:22Z")

</div>

i randomly sometime get this error

```auto
ConnectionError: unable to verify the first certificate
    at SniffingTransport.request (/home/ilsa/work/fayvo/nodeexpress/node_modules/@elastic/transport/lib/Transport.js:525:31)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async Client.SearchApi [as search] (/home/ilsa/work/fayvo/nodeexpress/node_modules/@elastic/elasticsearch/lib/api/api/search.js:65:12)
    at async data_aggregation (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:350:17)
    at async getAggregatedData (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:235:19)
    at async responseMapper (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:175:19)
    at async isFayvedMapper (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:161:24)
    at async get_results (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:97:27)
    at async exports.get_web (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/web_trend.js:81:23)
    at async Object.exports.get_trends (/home/ilsa/work/fayvo/nodeexpress/suggestion_list/api_caller.js:46:40)
    at async exports.get_trend (/home/ilsa/work/fayvo/nodeexpress/controllers/suggestionController.js:5:16) {
  meta: {
    body: undefined,
    statusCode: 0,
    headers: {},
    meta: {
      context: null,
      request: [Object],
      name: 'elasticsearch-js',
      connection: [Object],
      attempts: 3,
      aborted: false
    },
    warnings: [Getter]
  }
}

```

---

<div class="post-metadata">

**Author:** ![delvedor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/delvedor/32/67639_2.png) [@delvedor](https://discuss.elastic.co/u/delvedor)\
**Post date:** [February 23, 2022, 12:59pm UTC](https://discuss.elastic.co/t/connection-error-nodejsclient-8-0/298028/3 "2022-02-23T12:59:23Z")

</div>

Hello! Can you try the following code and let me know if you encounter the same issue?

```auto
const { Client, HttpConnection } = require('@elastic/elasticsearch')
const client = new Client({
  node: url.toString(),
  Connection: HttpConnection
})

```

---

<div class="post-metadata">

**Author:** ![dev\_test](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dev_test/32/79287_2.png) [@dev\_test](https://discuss.elastic.co/u/dev_test)\
**Post date:** [February 24, 2022, 7:21am UTC](https://discuss.elastic.co/t/connection-error-nodejsclient-8-0/298028/4 "2022-02-24T07:21:27Z")

</div>

hi, i have tried this but still i got error "ConnectionError: socket hang up - Local: 172.24.0.1:47080, Remote: 172.24.0.3:9200"

i want add a that even on browser I'm able to access the ip with a https request and going in unsafe mode and providing a username and password as well.  
I'm using the docker-compose file exactly same on this page [Install Elasticsearch with Docker | Elasticsearch Guide [8.0] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html)

mainly i need to understand from where this error is coming from and where do i need to put certificates for verifications

---

<div class="post-metadata">

**Author:** ![delvedor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/delvedor/32/67639_2.png) [@delvedor](https://discuss.elastic.co/u/delvedor)\
**Post date:** [February 24, 2022, 7:35am UTC](https://discuss.elastic.co/t/connection-error-nodejsclient-8-0/298028/5 "2022-02-24T07:35:36Z")

</div>

It looks like the problem is caused by a self-signed certificate, take a look [here](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/8.0/client-connecting.html#auth-tls) to see how to configure custom TLS options.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 24, 2022, 7:35am UTC](https://discuss.elastic.co/t/connection-error-nodejsclient-8-0/298028/6 "2022-03-24T07:35:42Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
