Languages
[Edit]
EN

Node.js - HTTP GET request using axios

0 points
Created by:
Cassia-Mendoza
415

In this article, we would like to show you how to make HTTP GET request using axios in Node.js.

Quick solution:

const axios = require('axios');

axios
  .get('/users')
  .then(function (response) {
    // handle success
    console.log(response.data);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .then(function () {
    // always executed
  });

 

Practical example

1. Install axios

npm install axios

2. Import axios using require()

const axios = require('axios');

3. Make async GET request

const axios = require('axios');

async function getUsers() {
  try {
    const response = await axios.get('http://localhost:5000/users');
    console.log(response.data);
  } catch (error) {
    console.error(error);
  }
}


// Usage example:

getUsers();

References

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join