我正在學習node.js,並且需要使用readline
作爲項目。我有以下代碼直接從readline module example。Node.js readline:意外的標記=>
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箭頭語法的。 – Tushar
升級你的節點 – DININDU
由於你的問題似乎已經解決,如果你能接受最好的答案,那將是非常好的。 – CherryDT