5

I'd like to make utilities in Node JS which can be used like:

node util.js | node util2.js 

just as you would using say

cat * | grep str 

etc.

1 Answer 1

3

Use the process.stdin and process.stdout streams.

Here's an example from those docs:

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'); }); 

Calling process.stdin.resume() starts the flow of data from standard input and will keep your program running until stdin is paused or ends.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.