I have a file "test.js" where I have a function that uses the 'request' module to get the response from a url. I call this function from another file, 'run.js' where I first store the return value and then print it out. I get 'undefined' as the output and I am unable to apply async/await to make it work. How can I make the console.log(res) to wait for the makeRequest() call to return a value?
test.js -
const request = require("request");
function makeRequest(url){
request(url, (error, response, html) => {
if(!error && response.statusCode == 200) {
return html;
} else {
console.log(error);
}
});
}
module.exports = makeRequest;
run.js -
const makeRequest = require("./test");
async function getResult(){
var res = await makeRequest("https://www.google.com");
console.log(res);
}