Skip to content

Instantly share code, notes, and snippets.

@syzer
Created January 17, 2018 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syzer/d0246a72d5516654d5a56cce26678b5b to your computer and use it in GitHub Desktop.
Save syzer/d0246a72d5516654d5a56cce26678b5b to your computer and use it in GitHub Desktop.
readline by line.. do not terminate, can use object-stream-tools
if (module.parent) {
return
}
const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
// terminal: false // isTTY
})
rl.on('line', (line) => {
console.log('line', line)
})
@syzer
Copy link
Author

syzer commented Jan 17, 2018

if (module.parent) {
  return
}
let chunks = ''
process.stdin.resume()
process.stdin.on('data', data =>
  chunks += data.toString())

process.stdin.on('end', async () => {
  process.stdout.write(await main(chunks), 'utf-8')
  process.exit(0)
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment