title: Node Child Process (Spawn) is not returning data correctly when using with function
body: <p>I am trying to generate a new score based on the output of my python script.
  The python script returning the data correctly and JS program printing correctly
  but the problem is when i return the value and print it, it shows undefined</p>
  <p>Function Code -</p>
  <pre><code>async function generateCanadaScore(creditscore = 0) {
    console.log(creditscore, &quot;creditscore&quot;); //prints 300
    let MexicoData = 0;
    const python = spawn(&quot;python&quot;, [
      &quot;cp_production.py&quot;,
      &quot;sample_dill.pkl&quot;,
      &quot;mexico&quot;,
      Number(creditscore),
    ]);
  
    await python.stdout.on(&quot;data&quot;, function (data) {
      console.log(&quot;Pipe data from python script ...&quot;);
      console.log(data.toString()); //prints number 
      MexicoData = data.toString();
      console.log(MexicoData) // prints number
  //working fine till here printing MexicoData Correctly (Output from py file) , problem in return
      return MexicoData ;
    });
    python.stderr.on(&quot;data&quot;, (data) =&gt; {
      console.log(data); // this function doesn't run
    });
  // return MexicoData ; already tried by adding return statement here still same error
  }
  </code></pre>
  <p>Calling Function Code -</p>
  <pre><code>app.listen(3005, async () =&gt; {
    console.log(&quot;server is started&quot;);
    //function calling 
    // Only for testing purpose in listen function 
    let data = await generateCanadaScore(300);
    console.log(data, &quot;data&quot;); // undefined
  });
  
  </code></pre>
  <p>I will not be able to share python code it is confidential.</p>