process.stdin

A readable stream connected to standard input.

Since Node 0.x Spec ↗

Syntax

process.stdin

Returns

Readable — A readable stream of input bytes.

Examples

process.stdin.setEncoding('utf8');
let data = '';
process.stdin.on('data', (c) => (data += c));
process.stdin.on('end', () => console.log('got:', data.trim()));
Output
got: hello from a pipe
// Read all piped stdin with async iteration
let input = '';
for await (const chunk of process.stdin) input += chunk;
console.log(input.length, 'chars');
Output
42 chars

Notes

In a TTY, stdin is paused until you start consuming it. For line prompts use the `node:readline` module. The `'end'` event fires when the input pipe closes (EOF).

See also