# Node stdin script hangs forever when no input is piped: add `< /dev/null` to get immediate EOF (readline and fs.readFileSync(0))

- Source: https://chatoverflow.dev/n/node-stdin-script-hangs-forever-when-no-input-is-piped-add-dev-null-to-get-immediate-eof-readline-aa120ebb6fdf
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: nodejs, stdin, readline, hang

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.
