axios async await nodejs code example

Example 1: async axios call

async getUserAsync(name) {
    try{
      let response = await axios({
          method: 'get',
          url: `https://api.github.com/users/${name}`,
          json: true
      });
      return response;
    } catch(err){
        console.error(err);
    }
}

Example 2: node js request async await

function doRequest(url) {
  return new Promise(function (resolve, reject) {
    request(url, function (error, res, body) {
      if (!error && res.statusCode == 200) {
        resolve(body);
      } else {
        reject(error);
      }
    });
  });
}

// Usage:

async function main() {
  let res = await doRequest(url);
  console.log(res);
}

main();