1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import * as readline from 'node:readline/promises' ; import { stdin as input, stdout as output } from 'node:process' ; import { Writable } from 'node:stream' ; var mutableStdout = new Writable({ write: function (chunk, encoding, callback) { if (! this .muted) output.write(chunk, encoding); callback(); } }); mutableStdout.muted = false ; var rl = readline.createInterface({ input: input, output: mutableStdout, terminal: true }); |
21 22 23 24 25 26 27 28 29 30 31 32 33 | const amount = await rl.question( 'Amount: ' ); output.write( 'Secret: ' ) mutableStdout.muted = true ; const secret = await rl.question(); output.write( '\n' ) console.log(`You entered: ${amount}, ${secret}`); rl.close(); |
This requires type
to be module
in package.json
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | { "type" : "module" , "name" : "xrp" , "version" : "1.0.0" , "description" : "" , "main" : "index.js" , "scripts" : { "test" : "echo \"Error: no test specified\" && exit 1" }, "author" : "" , "license" : "ISC" , "dependencies" : { "ripple-lib" : "^1.2.4" } } |