-1

This is my code and I have been trying to understand why data is always promise pending.

const axios = require('axios');
const { resolve,reject } = require('bluebird');


async function getData() {   
    const test = await axios.get(`http://localhost:3000/admin/dashboarddata/tabledata`).then((response)=>{
        return response
    }).catch();
    // console.log(test.data)
    var val = test
    return test;
  }
const data =  getData();
  
console.log(data)
James Z
  • 12,209
  • 10
  • 24
  • 44
  • Boy, Axios is a "promise based HTTP client." What else should it return? If you don't know how to use promises, a quick Google is all you need. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises. – code Apr 21 '22 at 19:06

1 Answers1

0

You might be able to get the data by awaiting the function to resolve. Give the following a shot:

const data = await getData()

instead of: const data = getData()

Hope it helps!

Amit Maraj
  • 344
  • 1
  • 5