1.0.3 • Published 5 years ago
readlin v1.0.3
We all know that reading lines in node is messy. That's exactly why I've come up with this solution
Here, we can convert this
const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
rl.question('What is your name? ', name => {
console.log('Your name is', name)
rl.close()
})
To something like this
const readLine = require('readlin')
readLine('What is your name? ')
.then(name => console.log('Your name is', name))
Or this
const readLine = require('readlin')
async function Main() {
const name = await readLine('What is your name? ')
console.log('Your name is', name)
}
Main()
Here, we can also pass a default value, that means if we dont pass anything in the input we will get the default value as the result.
readLine('What is your name? ', 'Ethan')
.then(name => console.log('Your name is', name))
Hello internet, I'm Ethan and this was the second package I published to npm. Please help me by posting your valuable ideas and suggestions on future packages at ethanlal04@gmail.com or visit my other packages at https://www.npmjs.com/~ethanlal. I'll see you soon. Take care :)