How to make the code below work with await
?
var readline = require('readline');
var Writable = require('stream').Writable;
var mutableStdout = new Writable({
write: function(chunk, encoding, callback) {
if (!this.muted)
process.stdout.write(chunk, encoding);
callback();
}
});
mutableStdout.muted = false;
var rl = readline.createInterface({
input: process.stdin,
output: mutableStdout,
terminal: true
});
//add await
rl.question('Amount: ', function(password) {
console.log('\nAmount is ' + password);
rl.close();
});
//add await
rl.question('Secret: ', function(password) {
console.log('\nSecret is ' + password);
rl.close();
});
mutableStdout.muted = true;
Secret
should be queried with mutableStdout.muted
set to true, and Amount
should be queried with mutableStdout.muted
set to false.
The both values should be saved to the variables amount
and secret
.
The code should work from the console with
node mycode.js