Categories
JavaScript Answers Nodejs

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *