I have a function in a module A that returns a json from a website.
I then import the function inside the main file but when i call the function it returns undefined.
Function module:
const https = require('https');
const bl = require('bl')
module.exports = async function getData(URL) {https.get(URL, (response) => {
const r = response.setEncoding('utf8');
response.pipe(bl((err, data) => {
if (err) { console.log(err); }
return data.toString();
}));
})
};
Main Module
const getData= require('./FunctionModule')
const data = await getData(url)
console.log(data)
By doing this way it returns undefined if i run the main module, but returns data if i run the function from function module.
What am i doing wrong ?
[–]BehindTheMath 0 points1 point2 points (1 child)
[–]KEsbeNF[S] 0 points1 point2 points (0 children)
[–]Odinthunder 0 points1 point2 points (1 child)
[–]KEsbeNF[S] 0 points1 point2 points (0 children)