Readline does not stop nor it can find prompt-sync

Trying to finish find the hat game in vanilla js but I can not get input from console either way. When I try to use prompt sync I get “Uncaught Error: ENXIO: no such device or address, open ‘/dev/tty’” error and “Uncaught Error: Cannot find module 'prompt-sync” even though npm and node are installed and up-to-date. When I try to use readline method it works but it does not continue even after my input.

const hat = '^'; const hole = 'O'; const fieldCharacter = '░'; const pathCharacter = '*'; let prompt = require('prompt-sync')(); class Field { constructor(map) { this._map = [ ["*","░","░"], ["░","0","░"], ["0","^","0"] ]; this._uinput = ""; } falldown(){ } printgame(){ let str = ""; for (const element of this._map) { for (const element2 of element) { str += element2; } console.log(str); str = ""; } } getUserInput(){ this._uinput = prompt("Where do we move?"); } game(){ let pcursor = this._map[0][0]; let xaxis = 0; let yaxis = 0; let counter = 1; console.log("Welcome to the hat game! Find the hat using WASD.") do{ this.printgame(); this.getUserInput(); if (this._uinput.toLowerCase() === "w"){ yaxis +=1; switch (yaxis) { case yaxis<0: console.log("You have fallen out of cliff"); return; case (yaxis)>this._map.length: console.log("You have fallen out of cliff"); return; } if (this._map[yaxis][xaxis] === "0"){ console.log("You have fallen in hole"); return; }else if (this._map[yaxis][xaxis] === "░"){ console.log("you can Continue...") this._map[yaxis].splice(xaxis,1,"*"); this.printgame(); } }else if (this._uinput.toLowerCase() === "s"){ yaxis +=1; switch (yaxis) { case yaxis<0: console.log("You have fallen out of cliff"); return; case (yaxis)>this._map.length: console.log("You have fallen out of cliff"); return; } if (this._map[yaxis][xaxis] === "0"){ console.log("You have fallen in hole"); return; }else if (this._map[yaxis][xaxis] === "░"){ this._map[yaxis].splice(xaxis,1,"*"); return; } } this._uinput = ""; }while(this._uinput !== ""); } } const gamee = new Field([ ["*","░","░"], ["░","0","░"], ["0","^","0"] ]); gamee.game();
const hat = '^'; const hole = 'O'; const fieldCharacter = '░'; const pathCharacter = '*'; const readline = require('readline').createInterface({ input: process.stdin, output: process.stdout }); class Field { constructor(map) { this._map = [ ["*","░","░"], ["░","0","░"], ["0","^","0"] ]; this._uinput = ""; } falldown(){ } printgame(){ let str = ""; for (const element of this._map) { for (const element2 of element) { str += element2; } console.log(str); str = ""; } } getUserInput(){ let uinputt = ""; readline.question('Who are you?', uinputt => { console.log("uinput"); readline.close(); readline.close(); return uinputt }); } game(){ let pcursor = this._map[0][0]; let xaxis = 0; let yaxis = 0; let counter = 1; console.log("Welcome to the hat game! Find the hat using WASD."); this.printgame(); let uput = this.getUserInput(); do{ if (uput === "w"){ yaxis +=1; switch (yaxis) { case yaxis<0: console.log("You have fallen out of cliff"); return; case (yaxis)>this._map.length: console.log("You have fallen out of cliff"); return; } if (this._map[yaxis][xaxis] === "0"){ console.log("You have fallen in hole"); return; }else if (this._map[yaxis][xaxis] === "░"){ console.log("you can Continue...") this._map[yaxis].splice(xaxis,1,"*"); this.printgame(); } }else if (uput === "s"){ yaxis +=1; switch (yaxis) { case yaxis<0: console.log("You have fallen out of cliff"); return; case (yaxis)>this._map.length: console.log("You have fallen out of cliff"); return; } if (this._map[yaxis][xaxis] === "0"){ console.log("You have fallen in hole"); return; }else if (this._map[yaxis][xaxis] === "░"){ this._map[yaxis].splice(xaxis,1,"*"); return; } } this._uinput = ""; }while(this._uinput !== ""); } } const gamee = new Field([ ["*","░","░"], ["░","0","░"], ["0","^","0"] ]); gamee.game();