我一直在这样做,以便在Linux下同步读取整个stdin数据:
var buffer = fs.readFileSync('/dev/stdin');
由于没有/ dev / stdin文件,因此这显然在Windows上不起作用。我该怎么做才能达到同样的目的?
readline-sync模块可以很好地完成这项工作。
npm install readline-sync
然后:
var readlineSync = require('readline-sync'); var answer = readlineSync.question('What is your favorite food? :'); console.log('Oh, so your favorite food is ' + answer);
https://www.npmjs.com/package/readline- sync