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
Function Code -
async function generateCanadaScore(creditscore = 0) {
console.log(creditscore, "creditscore"); //prints 300
let MexicoData = 0;
const python = spawn("python", [
"cp_production.py",
"sample_dill.pkl",
"mexico",
Number(creditscore),
]);
await python.stdout.on("data", function (data) {
console.log("Pipe data from python script ...");
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("data", (data) => {
console.log(data); // this function doesn't run
});
// return MexicoData ; already tried by adding return statement here still same error
}
Calling Function Code -
app.listen(3005, async () => {
console.log("server is started");
//function calling
// Only for testing purpose in listen function
let data = await generateCanadaScore(300);
console.log(data, "data"); // undefined
});
I will not be able to share python code it is confidential.