Back to TIL
May 2025
posted on 05.02.2025

Accessing stdin with file descriptor 0

In Node.js, you can access stdin using file descriptor 0 to take input stream:

const fs = require("fs");
const data = fs.readFileSync(0, "utf-8");

This can be used on the Node.js CLI:

echo Peter Mekhaeil | node -p "fs.readFileSync(0, 'utf8').toLowerCase().replaceAll(' ','-')"
No reactions yet

in Naperville, IL
Last visitor from Mitaka, Japan