I'm using fake-words
module (npm install fake-words
) with the following simple code:
#!/usr/bin/env node
const fake = require("fake-words");
while (true) {
console.log(fake.sentence());
}
When I run ./genwords.js
, everything works as expected.
However when I pipe into external program (on Ubuntu shell), the generation of words stops after a second.
$ ./genwords.js | cat
...
(output generation stops after a second)
$ ./genwords.js | tee
...
(stuck as well)
$ ./genwords.js | pv -l
...
4.64k 0:00:13 [0.00 /s]
Same happening when assigning a value to variable to avoid any caching (as precaution after reading this post, probably not relevant to Node.js):
while (true) {
words = fake.sentence();
console.log(words);
}
What I'm doing wrong?
I'm using Node v16 on Ubuntu:
$ node --version
v16.13.1