# Node.js Application Fail to Connect Elasticsearch

**URL:** <https://discuss.elastic.co/t/node-js-application-fail-to-connect-elasticsearch/348223>\
**Category:** Elasticsearch\
**Created:** [November 29, 2023, 11:32am UTC](https://discuss.elastic.co/t/node-js-application-fail-to-connect-elasticsearch/348223 "2023-11-29T11:32:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Burak\_Karatay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/burak_karatay/32/123772_2.png) [@Burak\_Karatay](https://discuss.elastic.co/u/Burak_Karatay)\
**Post date:** [November 29, 2023, 11:32am UTC](https://discuss.elastic.co/t/node-js-application-fail-to-connect-elasticsearch/348223/1 "2023-11-29T11:32:55Z")

</div>

I have very simple Node.js Application to connect my local Elasticsearch engine, when I try to use Kibana, I can connect after provide user and email but when I try to send ping from my Node.js app It gives following error:

ConnectionError: self-signed certificate in certificate chain

My code:

 ![Screenshot 2023-11-29 at 14.31.27](https://us1.discourse-cdn.com/elastic/original/3X/4/1/41f1f78cd36b4db6224522caf0d19eb1f99ad83d.png)

I don't understand the error message and I want this connection secure, I think I need to add certificate but I'm not sure how to do that

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [November 29, 2023, 11:55am UTC](https://discuss.elastic.co/t/node-js-application-fail-to-connect-elasticsearch/348223/2 "2023-11-29T11:55:25Z")

</div>

Hi @Burak_Karatay,

Welcome to the community! For future issues just a heads up that it's easier to read code as `code` text snippets rather than an image.

You're correct that the error relates to a certificate issue. There is an example of how to configure the certificate for the client in this [stackowerflow issue](https://stackoverflow.com/questions/62792477/cant-connect-to-elasticsearch-with-node-js-on-kubernetes-self-signed-certifica). Let us know if that solves the issue.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![Burak\_Karatay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/burak_karatay/32/123772_2.png) [@Burak\_Karatay](https://discuss.elastic.co/u/Burak_Karatay)\
**Post date:** [November 29, 2023, 12:20pm UTC](https://discuss.elastic.co/t/node-js-application-fail-to-connect-elasticsearch/348223/3 "2023-11-29T12:20:03Z")

</div>

Hi @carly.richmond ,  
Thank you so much for your answer.  
I saw this article but I don't know how to obtain elasticsearch\_certificate

```auto
ca: process.env.elasticsearch_certificate

```

```auto
const client = new elasticsearch.Client({
  node: process.env.elasticsearch_node,
  auth: {
    username: "elastic",
    password: process.env.elasticsearch_password || "changeme",
  },
  ssl: {
    ca: process.env.elasticsearch_certificate,
    rejectUnauthorized: false,
  },
});

```

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [November 29, 2023, 1:48pm UTC](https://discuss.elastic.co/t/node-js-application-fail-to-connect-elasticsearch/348223/4 "2023-11-29T13:48:58Z")

</div>

Hi @Burak_Karatay,

So you would need to specify the path to your certificate or the generated fingerprint when you start. There is more detail, and an example using tls [here in the documentation](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-connecting.html#connect-self-managed-new) that might help.

---

<div class="post-metadata">

**Author:** ![Burak\_Karatay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/burak_karatay/32/123772_2.png) [@Burak\_Karatay](https://discuss.elastic.co/u/Burak_Karatay)\
**Post date:** [November 30, 2023, 11:18am UTC](https://discuss.elastic.co/t/node-js-application-fail-to-connect-elasticsearch/348223/5 "2023-11-30T11:18:36Z")

</div>

Hi @carly.richmond ,

It worked with http\_ca.crt file thank you so much but now I want to connect with CA Fingerprint and to retrieve finger print I do this:

openssl x509 -in http\_ca.crt -noout -fingerprint

And I get a fingerprint, but the problem is when I try to connect with the given fingerprint like this:

```auto
import { Client } from "@elastic/elasticsearch";

const esClient = new Client({node: 'https://localhost:9200', auth: {username: 'elastic', password: 'password'}, 
caFingerprint: "fingerprint here",

tls: {rejectUnauthorized: false}})

```

I got this error:

ConnectionError: Server certificate CA fingerprint does not match the value configured in caFingerprint

---

<div class="post-metadata">

**Author:** ![Burak\_Karatay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/burak_karatay/32/123772_2.png) [@Burak\_Karatay](https://discuss.elastic.co/u/Burak_Karatay)\
**Post date:** [December 4, 2023, 11:50am UTC](https://discuss.elastic.co/t/node-js-application-fail-to-connect-elasticsearch/348223/6 "2023-12-04T11:50:27Z")

</div>

Hello @carly.richmond I need your help about another issue

> [@Elasticsearch Connection Error](https://discuss.elastic.co/t/elasticsearch-connection-error/348536):
>
> I have physical server with elasticsearch installed and from another computer I try to connect the elasticsearch with this code: const esClient = new Client({node: 'https://my-ip-address:5621', auth: {username: 'elastic', password: 'mypassword'}, caFingerprint: "91:9F:49:82:A0:5D:5A:2E:FA:3D..." tls: {rejectUnauthorized: false}}) I got this error: Error pinging server: ConnectionError: Invalid or malformed certificate I generated this fingerprint from the server, in the server there is a con…

---

<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:** [January 1, 2024, 11:50am UTC](https://discuss.elastic.co/t/node-js-application-fail-to-connect-elasticsearch/348223/7 "2024-01-01T11:50:42Z")

</div>

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