I'm currently facing this problem where I can't get a parent function to wait for a child function to retrieve some data and then having the parent function return the data.
In my case the child function is a callback of the  on method.
const parent = () => {
  ...
  let value;
  child.on('data', (data) => value = data);
  return value;
}
What I presume is happening here is that the parent function returns value before it gets anything assigned to it, thus making value equal to undefined. I am certain that I am recieving the desired data because when I log data within the callback I get the expected output.
So all and all what I would like to do is to make the parent function return the data which the child function recieves. I'm not entirely sure on how to go about from here.
I am very greatful for any help I can get.
 
    