1

I'm spawning npm install -g create-react-app from a js script. I want to know if it's possible to get the progress of the installation using spawn.

const npmExecutable = /^win/.test(process.platform) ? "npm.cmd" : "npm";
const npm = spawn(npmExecutable, ["install", "-g", "create-react-app"]);

I have read this question about using:

npm.on("message", data => {
  console.log(`A message: ${data}`);
});

but it does not show anything.

There is a related question, about knowing the progress of a python script, but it does not have any answers.

Does someone of you have tried something like that or know any clue about this?

Community
  • 1
  • 1
robe007
  • 3,523
  • 4
  • 33
  • 59
  • 2
    You probably want to use `npm.stdout.on('data', ...)`. The `child_process.on('message', ...)` event is for a process with an IPC channel, which is generally a child process created using `child_process.fork(...)`. – Jake Holzinger Mar 21 '19 at 18:19
  • Oh thanks. Now I can read the data, but what it shows is the _final output_ from the _npm command_, and not the progress of the execution of the command indeed, and that is what I really need. – robe007 Mar 21 '19 at 19:24
  • You will need to process the output of the program to determine it's progress, there is no built in progress monitor for a process. – Jake Holzinger Mar 21 '19 at 19:25
  • Yes, but ... what you mean by saying: _process the output of the program to determine it's progress_ ? – robe007 Mar 21 '19 at 19:27
  • According to the [`npm config`](https://docs.npmjs.com/misc/config#progress) documentation you can listen to `stderr` to get the progress information. It says that `stderr` must be a `TTY`, I don't know what that means or how to parse the data, but that is where you will want to look. – Jake Holzinger Mar 22 '19 at 00:37

0 Answers0