我想做一個(gè)帶有控制臺(tái)擴(kuò)展的簡(jiǎn)單服務(wù)器http服務(wù)器。我找到了要從命令行數(shù)據(jù)讀取的代碼段。 var i = rl.createInterface(process.stdin, process.stdout, null); i.question('Write your name: ', function(answer) { console.log('Nice to meet you> ' + answer); i.close(); process.stdin.destroy(); });好再問一次問題,我不能簡(jiǎn)單地使用while(done) { }循環(huán)?如果服務(wù)器在詢問時(shí)間接收到輸出,也會(huì)破壞線路。
3 回答

慕運(yùn)維8079593
TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊
自12英尺以來,Readline API發(fā)生了很大變化。該文檔顯示了一個(gè)有用的示例,可以從標(biāo)準(zhǔn)流中捕獲用戶輸入:
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('What do you think of Node.js? ', (answer) => {
console.log('Thank you for your valuable feedback:', answer);
rl.close();
});
- 3 回答
- 0 關(guān)注
- 636 瀏覽
添加回答
舉報(bào)
0/150
提交
取消