L
L
Lans2020-11-21 18:21:53
Node.js
Lans, 2020-11-21 18:21:53

Sending commands to child_process?

I have a code that spawns a child process (server) via spawn() and sends data to the console:

var cp = require('child_process');

var child = cp.spawn('./server');
child.stdout.on('data', function(data) {
  console.log(data.toString())
});

The server is always running. I need to send a certain command there ("stop", "restart"), but I can't do it.
We need the ability to be able to send a command at any time.
How can I do it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question