# React Axios Elasticsearch

**URL:** <https://discuss.elastic.co/t/react-axios-elasticsearch/263645>\
**Category:** Elasticsearch\
**Created:** [February 8, 2021, 6:25pm UTC](https://discuss.elastic.co/t/react-axios-elasticsearch/263645 "2021-02-08T18:25:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmedch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmedch/32/83589_2.png) [@ahmedch](https://discuss.elastic.co/u/ahmedch)\
**Post date:** [February 8, 2021, 6:25pm UTC](https://discuss.elastic.co/t/react-axios-elasticsearch/263645/1 "2021-02-08T18:25:05Z")

</div>

Hello,  
I am working on a react app using elasticsearch , I have a problem for making post request with axios , the app is mainly based on react and Elasticsearch  
.  
This is the code working on node.js

```
const axios = require('axios');
const fs = require('fs');
const filePath = __dirname + '/products-bulk.json';

const indexName = 'indexrandom881';
const url = `http://localhost:9200/${indexName}/_bulk`;

fs.readFile(filePath, async (err, jsonData) => {
if (err) {
    console.error({ err });
    return;
}

const { data } = await axios.post(url, jsonData, {
    headers: {
        'Content-Type': 'application/x-ndjson'
    }
});

console.info({ data });
});

```

I want to make it working on react or at least execute node.js code through react or html code  
, this is my essay:

```auto
    function App() {
    const axios = require('axios');
    const fs = require('fs');
    const filePath = __dirname + '/national-es-bulk-index22.json';
    const indexName = 'indexrandom881';
    const url = `http://localhost:9200/${indexName}/_bulk`;
    fs.readFile(filePath, async (err, jsonData) => {
        if (err) {
            console.error({ err });
            return;
        }

        const { data } = await axios.post(url, jsonData, {
            headers: {
                'Content-Type': 'application/x-ndjson'
            }
        });

        console.info({ data });
    });
    return (
    <div className="App">
        <h1>test</h1>
    </div>
    );
    }

    export default App;

```

Thanks in advance

---

<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 8, 2021, 6:25pm UTC](https://discuss.elastic.co/t/react-axios-elasticsearch/263645/2 "2021-03-08T18:25:33Z")

</div>

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