Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
Getting data with axios and posting to localhost using express

I am new to javascript and am trying to fetch data from an API then post it to my own server (localhost).

I get the data using axios below:

async function getNCAA() {
    axios
    .get(`https://api.the-odds-api.com/v4/sports/${sportKey1}/scores/?daysFrom=1&apiKey=${apiKey}`)
    .then((res) => {
        console.log(res.data)
        console.log("Remaining requests", res.headers["x-requests-remaining"]);
        console.log("Used requests", res.headers["x-requests-used"]);
        return res.data
    })
    .catch((error) => {
        console.log("Error status", error.response.status);
        console.log(error.response.data);
        return error
    });
}

assign the data

let result = getNCAA();

then try to send it using express:

app.get('/', (req, res) => {
    res.send(result);
});

The result returns a Promise object that I don't know how to access.

I've been able to access this data in the past by using a useState but I am not running a React app in this particular case

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Not sure if it's good practice but I just nested it all together and it works.

async function getNCAA() {
    axios
    .get(`https://api.the-odds-api.com/v4/sports/${sportKey1}/scores/?daysFrom=1&apiKey=${apiKey}`)
    .then((result) => {
        // console.log(res.data)
        console.log("Remaining requests", result.headers["x-requests-remaining"]);
        console.log("Used requests", result.headers["x-requests-used"]);

        app.get('/', (req, res) => {
            res.send(result.data);
        });
        })
    .catch((error) => {
        console.log("Error status", error);
    });

    return ;
}

getNCAA();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda