Created
May 20, 2018 14:47
-
-
Save nairihar/05f8f8f883d701dfbe3a0ebaf17499ae to your computer and use it in GitHub Desktop.
AsyncIteration using FS, Async Iterator in NodeJS v10, medium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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