Categories
JavaScript Answers

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

Spread the love

To wait for a child process to finish in Node.js, we listen for the exit event.

For instance, we write

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

child.stdout.pipe(process.stdout);
child.on("exit", () => {
  process.exit();
});

to call on with 'exit' to listen for the exit event, which is emitted when the process is finished.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.