# Unable to connect elastic search with node.js client

**URL:** <https://discuss.elastic.co/t/unable-to-connect-elastic-search-with-node-js-client/193084>\
**Category:** Elasticsearch\
**Created:** [July 31, 2019, 9:44am UTC](https://discuss.elastic.co/t/unable-to-connect-elastic-search-with-node-js-client/193084 "2019-07-31T09:44:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jin1129](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jin1129/32/37454_2.png) [@Jin1129](https://discuss.elastic.co/u/Jin1129)\
**Post date:** [July 31, 2019, 9:44am UTC](https://discuss.elastic.co/t/unable-to-connect-elastic-search-with-node-js-client/193084/1 "2019-07-31T09:44:52Z")

</div>

I'm trying to use elastic search client for node.js

I was able to get a response with my curl command

However, my client for node.js it didn't print out any result or error message.

my working Curl is shown as follow

```auto
curl -X GET -H 'Content-Type:application/json' -u 'username:password' https://venus.example.com/my_example_index/_search -d '
{"query":{"bool":{"must":[{"term":{"main.message.neworder":true}}],"must_not":[],"should":[]}},"from":0,"size":10,"sort":[],"aggs":{}}'i

```

some part of my node.js codes for the elastic connection is shown as follow

```auto
function getElastic() {

const { Client } = require('@elastic/elasticsearch');
const { URL } = require('url');

    const client = new Client({
       
        node: {
            url: new URL('https://venus.example.com'),
            username: 'username',
            password: 'password',
        },
    });

  let body = async () => {
        try {
            return await client.search({
                index: 'my_example_index',
                body: {
                    query: {
                        bool: {
                            must: [{ term: { 'main.message.neworder': true } }],
                            must_not: [],
                            should: [],
                        },
                    },
                },
            });
        } catch (error) {
            console.error(error);
        }
    };
}

```

please give me some useful advice to get a successful result.

---

<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:** [August 28, 2019, 9:51am UTC](https://discuss.elastic.co/t/unable-to-connect-elastic-search-with-node-js-client/193084/2 "2019-08-28T09:51:01Z")

</div>

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