【发布时间】:2019-09-05 01:06:47
【问题描述】:
我正在尝试从 repl.it 终端读取一些输入,但程序在 readline 接口关闭之前终止。
我目前正在使用 node.js 直接提供的代码。我从中获取文档的链接是here
这是我的代码的全部:
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('What do you think of Node.js? ', (answer) => {
// TODO: Log the answer in a database
console.log(`Thank you for your valuable feedback: ${answer}`);
rl.close();
});
预期结果:问题出现,程序等待答案。然后,它记录Thank you for your valuable feedback: <answer-here> 并终止
【问题讨论】:
-
我不确定 repl.it,但是如果你将代码复制到一个 js 文件(即
index.js)并使用node index.js运行它,它完全符合你的要求期待。 -
你能分享 repl.it 链接吗?