I am trying to get the http get response from async function.However within the function value is displaying but return values is undefined.
Even promise not undefined values
please find code below
'use strict';
const express = require('express');
var request = require('request');
var https = require('https');
async function getCurrencies() {
let response;
try {
var getOptions = {
url: 'http://localhost:3000/api/currency',
method: 'GET',
headers: {
'Content-Type': 'application/json'
},
json:true
};
await request(getOptions, function (err, res, body) {
if (res && (res.statusCode === 200 || res.statusCode === 201)) {
console.log(' response ', res.body.rates.INR);
return res.body;
} else {
console.log('error body ', body);
}
});
} catch (error) {
console.log(" error pulling ", error);
process.exit();
}
}
var tt = getCurrencies().then(function(value) {
console.log(' tt values ',value);
}
);
below is the logs
tt values undefined
response 64.945