I am learning NodeJS, and I wrote a simple function that makes an https get request and returns the response in a promise, which then gets logged. However, I get no response at all. Can anyone tell me why?
funcs.js
const https = require("https")
const makeGetReq = async (url) => {
var response = ""
https.get(url, (res) => {
res.on("data", (chunk) => {
response += chunk
})
res.on("end", () => {
return response
})
}).on("error", (err) => {
return err
})
}
module.exports = { makeGetReq: makeGetReq }
main.js
const { makeGetReq } = require("./funcs")
makeGetReq("https://www.google.com")
.then((response) => {
console.log(`${response}`)
})
OUTPUT:
undefined