1const readFromStdin = async () => new Promise((resolve, reject) => { 2 const encoding = 'utf-8' 3 let data 4 data = '' 5 process.stdin.setEncoding(encoding) 6 process.stdin.on('readable', function () { 7 const chunk = process.stdin.read() 8 if (chunk !== null) { 9 data += chunk 10 } 11 }) 12 process.stdin.on('error', (error) => { 13 reject(error) 14 }) 15 process.stdin.on('end', function () { 16 // There will be a trailing \n from the user hitting enter. Get rid of it. 17 data = data.replace(/\n$/, '') 18 resolve(data) 19 }) 20}) 21 22module.exports = { 23 read: readFromStdin 24} 25