Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
Posting result of axios

Currently have this piece of code it gets me the data i need but idk how to post/showcase the data on the website page and not the console file? i tried post and everything i could think of

const express = require('express');
const app = express();
app.listen(3000, () =>console.log('success'));
app.use(express.static('public'));


var axios = require('axios');
const { response } = require('express');

var config = {
 // method -> 'get', 'post', 'delete', 'put'
  method: 'get',
  // API endpoint -> 'https://api.eventyay.com/v1/event-locations'; 
  // API endpoint with query parameters -> 'https://api.eventyay.com/v1/event-locations?sort=name'
  url: 'https://api.eventyay.com/v1/event-locations',
  // sindle header -> header: { 'key': 'value'}
  // multiple header -> header: { 'key': 'value', 'key': 'value'}
  headers: { }
};

// If API response is success then would be executed, else catch block would be executed.
axios(config).then((response) => {
    // data = response.data
    // To parse data to json -> JSON.parse(response.data)
    // To parse data to string -> JSON.stringify(response.data)
  console.log(JSON.stringify(response.data))
  return response.data;
})
.catch((error) => {
  console.log(error)
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try this code, it listens to /my-api-path and returns the result.

const express = require('express')
const app = express()
const port = 3000
var axios = require('axios');

app.use(express.static('public'));

app.get('/my-api-path', (req, res) => {
  var config = {
 // method -> 'get', 'post', 'delete', 'put'
  method: 'get',
  // API endpoint -> 'https://api.eventyay.com/v1/event-locations'; 
  // API endpoint with query parameters -> 'https://api.eventyay.com/v1/event-locations?sort=name'
  url: 'https://api.eventyay.com/v1/event-locations',
  // sindle header -> header: { 'key': 'value'}
  // multiple header -> header: { 'key': 'value', 'key': 'value'}
  headers: { }
};

// If API response is success then would be executed, else catch block would be executed.
axios(config).then((response) => {
    // data = response.data
    // To parse data to json -> JSON.parse(response.data)
    // To parse data to string -> JSON.stringify(response.data)
  console.log(JSON.stringify(response.data))
  res.send(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error)
res.send("Error "+error.toString());
});
})

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda