nodejs 命令行交互
人机交互
function readSyncByfs(tips) { tips = tips || '> '; process.stdout.write(tips); process.stdin.pause(); const buf = Buffer.allocUnsafe(10000); let response = fs.readSync(process.stdin.fd, buf, 0, 10000, 0); process.stdin.end(); return buf.toString('utf8', 0, response).trim(); } var a = readSyncByfs('请输入任意字符:'); var a = readSyncByfs(''); console.log(a);