Is it possible to synchronously read from stdin in node.js? Because I\'m writing a brainfuck to JavaScript compiler in JavaScript (just for fun). Brainfuck supports a read o
After fiddling with this for a bit, I found the answer:
process.stdin.resume();
var fs = require('fs');
var response = fs.readSync(process.stdin.fd, 100, 0, "utf8");
process.stdin.pause();
response will be an array with two indexes, the first being the data typed into the console and the second will be the length of the data including the newline character.
It was pretty easy to determine when you console.log(process.stdin)
which enumerates all of the properties including one labeled fd
which is of course the name of the first parameter for fs.readSync()
Enjoy! :D