我正在学习nodejs并遇到错误。在readline.question()中定义回调并传递参数后,我得到TypeError:回调不是一个函数。请帮助我。
rl.question("./dict ", function(inputDictCmd, callback) {
if(inputDictCmd){
var userInput = inputDictCmd.split(" ");
if(userInput.length === 2){
var opr = userInput[0];
var word = userInput[1];
var requestUrl = "www.xyz.com"
if(opr && opr === 'defn' || opr === 'syn' || opr === 'ant' || opr === 'ex'){
if(opr === 'defn'){
var requestType = 'definitions';
request.get(requestUrl, function (err, res) {
callback("SJDKFD");
return callback;
});
}
}
}
}
rl.close();
});
从阅读行documentation:
传递给rl.question()的回调函数并不遵循接受Error对象或将null作为第一个参数的典型模式。使用提供的答案作为唯一参数调用回调。
您传递给rl.question的回调有2个参数。