Skip to content

Instantly share code, notes, and snippets.

@thiagomr
Created March 20, 2018 04:10
Show Gist options
  • Select an option

  • Save thiagomr/8e225863bc27fd4ceac65b5c93cff836 to your computer and use it in GitHub Desktop.

Select an option

Save thiagomr/8e225863bc27fd4ceac65b5c93cff836 to your computer and use it in GitHub Desktop.
import fs from 'fs';
import readline from 'readline';
async function process() {
return new Promise((resolve, reject) => {
let stream = fs.createReadStream('/tmp/file.txt');
let rl = readline.createInterface({
input: stream
});
rl.on('line', (line) => {
console.log(line);
}).on('close', () => {
resolve('finished');
}).on('error', err => {
reject(err);
})
});
}
(async function () {
try {
const result = await process();
console.log(result)
} catch (e) {
console.error(e);
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment