How to wait for a child process to finish in Node.js?

NodeJS supports doing this synchronously.
Use this:

const execSync = require("child_process").execSync;
    
const result = execSync("python celulas.py");
    
// convert and show the output.
console.log(result.toString("utf8"));

Remember to convert the buffer into a string. Otherwise you'll just be left with hex code.


A simple way to wait the end of a process in nodejs is :

const child = require('child_process').exec('python celulas.py')

await new Promise( (resolve) => {
    child.on('close', resolve)
})

Use exit event for the child process.

var child = require('child_process').exec('python celulas.py')
child.stdout.pipe(process.stdout)
child.on('exit', function() {
  process.exit()
})

PS: It's not really a duplicate, since you don't want to use sync code unless you really really need it.