Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Publicar resultado de axios

Actualmente tengo este fragmento de código que me proporciona los datos que necesito, pero no sé cómo publicar/mostrar los datos en la página del sitio web y no en el archivo de la consola. Intenté publicar y todo lo que se me ocurrió

 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 answers
Answer question

0

Pruebe este código, escucha /my-api-path y devuelve el resultado.

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!