How to call a web service using Node.js and JavaScript?

Sometimes, we want to call a web service using Node.js and JavaScript.

In this article, we’ll look at how to call a web service using Node.js and JavaScript.

How to call a web service using Node.js and JavaScript?

To call a web service using Node.js and JavaScript, we can use Axios.

To install it, we run:

npm i axios

Then we can use it by writing:

const axios = require('axios')

const get = async () => {
  const { data } = await axios.get('https://google.com')
  console.log(data)
}
get()

We call axios.get to make a GET request to https://google.com.

And we get the response from data.

Conclusion

To call a web service using Node.js and JavaScript, we can use Axios.