Skip to content

Instantly share code, notes, and snippets.

@nairihar
Created May 20, 2018 14:47
Show Gist options
  • Save nairihar/05f8f8f883d701dfbe3a0ebaf17499ae to your computer and use it in GitHub Desktop.
Save nairihar/05f8f8f883d701dfbe3a0ebaf17499ae to your computer and use it in GitHub Desktop.
AsyncIteration using FS, Async Iterator in NodeJS v10, medium
const express = require('express');
const fs = require('fs');
const app = express();
app.get('/', async (req, res) => {
const stream = fs.createReadStream('file_name', {
highWaterMark: 5
});
for await (const chunk of stream) {
res.write(`Read ${chunk}`);
}
res.end('Hello World!');
})
app.listen(3000);
console.log('Server running at 3000 port');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment