Q: "While" blocking async operation When I am trying to run that code -
const MagicHomeControl = require("magic-home").Control;
const readlineSync = require("readline-sync");

const light = new MagicHomeControl("192.168.1.77");

let answer;

while(true){
    answer = readlineSync.question("What do you wish to do?\nTurn on - on\nTurn off - off\nQuit the program - quit\n");
    switch(answer){
        case "on":
            light.turnOn(function(err, success){

            });
            break;
        case "off":
            light.turnOff(function(err, success){

            });
            break;
        case "quit":
            process.exit(-1);
            break;
        default:
            console.log("Wrong input, try again");
            break;
    }
}

Only quit option work right. But if i write the same code, but without while loop = everything's working fine, but only one time. Any ideas?

A: After calling turnOn or turnOff you immediately call readlineSync.question, which could possibly block any possibility for the API behind turnOn or turnOff functions to complete, or at least to report back to JavaScript.
You could work around that by making your loop asynchronous, and only "iterate" when the turnOn or turnOff operation is completed:
(function loop(err, success) {
    if (err) console.log(err);
    const answer = readlineSync.question("What do you wish to do?\nTurn on - on\nTurn off - off\nQuit the program - quit\n");
    switch(answer){
    case "on":
        light.turnOn(loop);
        break;
    case "off":
        light.turnOff(loop);
        break;
    case "quit":
        process.exit(-1);
        break;
    default:
        console.log("Wrong input, try again");
        setTimeout(loop); // Also do this asynchronously to save the stack.
    }
})(); // IIFE - immediately invoked function expression

