R
R
ratatyq2017-04-20 12:36:13
Node.js
ratatyq, 2017-04-20 12:36:13

How to handle keys in node js cmd console?

Hello, is there a way to handle keyboard presses in the console of a node js application?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aleksandr Salamatov, 2017-04-20
@ratatyq

npm install readline

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

rl.question("Enter you name:", function(name) {
    console.log(`Your name: ${name}`);
});

Upd: If just pressing https://www.npmjs.com/package/keypress

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question