Overview:

If you have ever thought about calling python scripts from a node application, then heres what worked for me. (because Python AI / ML libs are awesome)

Option one

let runPy = () => new Promise(function(resolve, reject) {
  console.log("runPy")
  const { spawn } = require('child_process');
  const pyprog = spawn('python', ['./pythonScripts/script.py']);

  pyprog.stdout.on('data', function(data: any) {
    console.log("stdout")
    resolve(data.toString());
  });

  pyprog.stderr.on('data', (data: any) => {
    console.log("stderr")
    reject(data);
  });
});
  const result = await runPy()
  console.log("getServerSideProps", result)
  const pythonProcess = spawn('python',["./pythonScripts/script.py"]);
  pythonProcess.stdout.on('data', (data)=> {
    console.log(data);
    return data
  })