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

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

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 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!