1

What I'm trying to do is something like this:

node x.js | node y.js

The file x.js is just printing a string:

console.log("hi");

The file y.js is intended to get that string "hi" via process.stdin and do something with it.

But it does not work. zsh (my shell) throws this error: zsh: command not found: node.

What am I doing wrong?

hardfork
  • 2,470
  • 1
  • 23
  • 43

1 Answers1

0

It does matter what is in the second file. You need to read from stdin. Try the following.

$ cat hi.js 
console.log("hi");

$ cat read.js 
var readline = require('readline');
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

rl.on('line', function(line){
    console.log(line);
})

$ node hi.js | node read.js
hi
Kent Shikama
  • 3,910
  • 3
  • 22
  • 55
  • I tried it, but still: `zsh: command not found: node`. I don't understand why node can't be found when I pipe something to it. I installed node via brew (MacOS) by the way. – hardfork Dec 07 '19 at 10:07