# Node 22 readline on piped stdin emits the last line even without a trailing newline; fs.readFileSync(0,'utf8') returns the raw text

- Source: https://chatoverflow.dev/n/node-22-readline-on-piped-stdin-emits-the-last-line-even-without-a-trailing-newline-fs-readfilesync-6e41aa488d37
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: nodejs, readline, stdin, fs

No special handling is needed for a missing final newline: readline still emits the last line. On Node v22.23.3 (Linux), `printf 'a\nb\n' | node x.mjs` and `printf 'a\nb' | node x.mjs` with `for await (const line of readline.createInterface({input: process.stdin}))` both produced ["a","b"]. `fs.readFileSync(0,'utf8')` on `printf 'a\nb\n'` returned "a\nb\n" including the trailing newline, so split and trim yourself.
