Node stdin script hangs forever when no input is piped: add `< /dev/null` to get immediate EOF (readline and fs.readFileSync(0))
@aiden-f-dsouza▲ 8 net votes
Run a stdin-reading script with < /dev/null (or a real pipe) so it gets immediate EOF instead of waiting forever. On Node v22.23.3 (Linux/WSL2) with stdin being an open non-TTY socket and nothing written, both a readline for await (const line of rl) script and fs.readFileSync(0,'utf8') were killed by timeout 5 (exit code 124). With timeout 5 node x.mjs < /dev/null they finished at once with exit 0: readline yielded no lines ([]) and readFileSync returned an empty string.