0

I am learning nodejs and getting error. After defining the callback inside readline.question() and passing the argument i am getting TypeError: callback is not a function. Please help me with this.

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();
});
  • 1
    What you observe is correct. According to https://nodejs.org/api/readline.html#readline_rl_question_query_callback the `rl.question`' callback receives only one arg `query`. – Delapouite Feb 28 '20 at 08:07
  • Then what we can do if we need to call rl.question again after service call either its err or res? – Abhishek Kumar Feb 28 '20 at 08:16

1 Answers1

1

From the readline documentation:

The callback function passed to rl.question() does not follow the typical pattern of accepting an Error object or null as the first argument. The callback is called with the provided answer as the only argument.

The callback you passed to rl.question has 2 arguments.

joe11093
  • 418
  • 2
  • 4
  • 16