# Inject data with Node.js on Elasticsearch service

**URL:** <https://discuss.elastic.co/t/inject-data-with-node-js-on-elasticsearch-service/337474>\
**Category:** Elasticsearch\
**Created:** [July 3, 2023, 2:29pm UTC](https://discuss.elastic.co/t/inject-data-with-node-js-on-elasticsearch-service/337474 "2023-07-03T14:29:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sheereen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sheereen/32/122005_2.png) [@Sheereen](https://discuss.elastic.co/u/Sheereen)\
**Post date:** [July 3, 2023, 2:29pm UTC](https://discuss.elastic.co/t/inject-data-with-node-js-on-elasticsearch-service/337474/1 "2023-07-03T14:29:19Z")

</div>

Hi,

I want to ingest data on Elasticsearch using a Node.js backend. The following link has instructions regarding how to the same on Elastic Cloud deployment ([Ingest data with Node.js on Elasticsearch Service | Elasticsearch Service Documentation | Elastic](https://www.elastic.co/guide/en/cloud/current/ec-getting-started-node-js.html)). How can I do it in a local deployment ?

Thanks

---

<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:** [July 3, 2023, 3:00pm UTC](https://discuss.elastic.co/t/inject-data-with-node-js-on-elasticsearch-service/337474/2 "2023-07-03T15:00:20Z")

</div>

Hi @Sheereen,

You'll need to specify the local deployment as the `node` parameter along with the required authentication params as `auth` dEpending on the security settings of your deployment. I would recommend taking a look at the [JavaScript client connection documentation for self-managed](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-connecting.html#connect-self-managed-new).

Hope that helps!

---

<div class="post-metadata">

**Author:** ![Sheereen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sheereen/32/122005_2.png) [@Sheereen](https://discuss.elastic.co/u/Sheereen)\
**Post date:** [July 3, 2023, 3:04pm UTC](https://discuss.elastic.co/t/inject-data-with-node-js-on-elasticsearch-service/337474/3 "2023-07-03T15:04:36Z")

</div>

Thanks a lot.... was looking for this documentation.

I will try it out and let u know.

---

<div class="post-metadata">

**Author:** ![Sheereen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sheereen/32/122005_2.png) [@Sheereen](https://discuss.elastic.co/u/Sheereen)\
**Post date:** [July 3, 2023, 3:30pm UTC](https://discuss.elastic.co/t/inject-data-with-node-js-on-elasticsearch-service/337474/4 "2023-07-03T15:30:31Z")

</div>

I am having trouble with certficates. Got the following error:

```auto
ConnectionError: self signed certificate in certificate chain
    at ClientRequest.onError (/root/Backend/ApiGateway/node_modules/@elastic/elasticsearch/lib/Connection.js:123:16)
    at ClientRequest.emit (node:events:527:28)
    at TLSSocket.socketErrorListener (node:_http_client:454:9)
    at TLSSocket.emit (node:events:527:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

```

The below is my server.js (node js file)

```auto
const client = new Client({
  node: elasticConfig.node,
  auth: {
    username: elasticConfig.username,
    password: elasticConfig.password
  },
  tls: {
    ca: fs.readFileSync(elasticConfig.ca),
    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:** [July 3, 2023, 3:35pm UTC](https://discuss.elastic.co/t/inject-data-with-node-js-on-elasticsearch-service/337474/5 "2023-07-03T15:35:06Z")

</div>

Thanks for the update. I did come across [this StackOverflow thread](https://stackoverflow.com/questions/62792477/cant-connect-to-elasticsearch-with-node-js-on-kubernetes-self-signed-certifica) with a similar issue. Can you try `rejectUnauthorized: true` and also check the cert as it suggests?

Let us know if that solves the problem!

---

<div class="post-metadata">

**Author:** ![Sheereen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sheereen/32/122005_2.png) [@Sheereen](https://discuss.elastic.co/u/Sheereen)\
**Post date:** [July 3, 2023, 3:44pm UTC](https://discuss.elastic.co/t/inject-data-with-node-js-on-elasticsearch-service/337474/6 "2023-07-03T15:44:27Z")

</div>

> [@carly.richmond](#):
>
> `true`

By default, in /etc/elasticsearch, I found a **http\_ca.crt** file. I used the same as the ca certificate. Should I generate another in pem format?

---

<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:** [July 31, 2023, 3:45pm UTC](https://discuss.elastic.co/t/inject-data-with-node-js-on-elasticsearch-service/337474/7 "2023-07-31T15:45:12Z")

</div>

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