Get the latest tech news

Node.js, Pipes, and Disappearing Bytes


bytes 2024 Oct 09 Someone in one of my online communities recently asked about why their Node command was dropping output when piped to another command: [command] spits out 2319 lines of valid json to stdout. If I redirect it into a file then I can open that file and yes, see all 2319 lines and well formatted json.

If you've looked up the documentation for printf or std::cout or process.stdout.write enough times, you'll notice - and hopefully remember - that they all make some mention of buffering and blocking, which you usually just gloss over because it's entirely irrelevant to what you're doing. This may not be a problem when writing to an interactive terminal session, but consider this particularly careful when doing production logging to the process output streams. They did both point out that to fix this, there's a drain event that you can subscribe to, so you can resume writing to stdout after process.stdout has filled up; but nothing that either suggested was repro'ing this issue.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of pipes

pipes

Photo of Node.js

Node.js

Photo of Disappearing Bytes

Disappearing Bytes

Related news:

News photo

Show HN: Pipet – CLI tool for scraping and extracting data online, with pipes

News photo

Node.js adds experimental support for TypeScript

News photo

Node.js Is Here to Stay