MeetCode - Programming Platform | MeetCode - Programming Solutions Platform

NodeJS Program to PassThrough Logger with Explanation

NodeJS Medium Streams & Buffers 31 views
This problem helps you practice core NodeJS fundamentals in a practical way. It builds intuition around byte, passthrough, count. Let’s break it down step by step so you can implement it confidently.
Back to Questions

Problem Statement

Use PassThrough to tap into a stream and count bytes.

Input Format

stdin: any text.

Output Format

Print integer bytes.

Constraints

Count bytes flowing through.

Code Solution

This explanation is written for learning purposes and to help beginners understand the concept clearly.
const { PassThrough } = require('stream'); let bytes = 0; const tap = new PassThrough(); tap.on('data', (c) => { bytes += c.length; }); process.stdin.pipe(tap).resume(); process.stdin.on('end', () => console.log(bytes));

Output Example

Input:
meetcode
Output:
7

Common Mistakes

- Misreading input/output format.
- Not handling constraints and edge cases.
- Off-by-one errors in loops.
- Forgetting to reset variables between test cases (if any).

Notes & Extra Practice

Solutions (0)

No solutions submitted yet. Be the first!

Prev Next