【发布时间】:2016-08-19 00:30:35
【问题描述】:
我正在学习 node.js,需要在一个项目中使用readline。我直接从readline module example 获得了以下代码。
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();
});
但是当我通过
node try.js 命令,它不断给出如下错误:
rl.question('What is your favorite food?', (answer) => {
^^
SyntaxError: Unexpected token =>
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
【问题讨论】:
-
您使用的是什么版本的节点?可能是不支持 ES6 箭头语法的那个。
-
@CherryDT 刚刚做了。抱歉,社区新手
标签: javascript node.js readline console.readline