Converting getExchangeRate and getCountries into the async function

So the first thing we're going to do is convert getExchangeRate and getCountries. The first step I'm going to take is to make this an async function, otherwise we can't use await. Then we're going to go ahead and set up a variable, a const response, and we are going to set this equal to await. Then we're going to await the following promise, the one that comes back from axios.get. I'm going to copy it, paste it, toss a semicolon at the end, and the only thing left to do is to return the value. I'm going to take the return statement and move it right there, then we can remove all of the previous code we had:

const getExchangeRate = async (from, to) => { const response = await ...

Get Advanced Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.