Create programs that can be transmitted via node.js channels

I would like to make utilities in Node JS that can be used as:

node util.js | node util2.js

how could you use

cat * | grep str

and etc.

+5
source share
1 answer

Use process.stdinand process.stdoutthreads.

Here is an example from these documents:

process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
  process.stdout.write('data: ' + chunk);
});

process.stdin.on('end', function () {
  process.stdout.write('end');
});

The call process.stdin.resume()starts the data stream from standard input and will support your program until stdin stops or ends.

+3
source

All Articles