Last active
August 3, 2022 09:32
-
-
Save myas92/f90261a9aace3c1e571a8bc7d0c71d24 to your computer and use it in GitHub Desktop.
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 app = express(); | |
const fs = require('fs'); | |
app.get('/', (req, res) => { | |
const { size } = fs.statSync('input.txt'); | |
const readStreamfile = fs.createReadStream('input.txt', { | |
encoding: 'UTF-8', | |
start: 0, | |
end: size, | |
highWaterMark: 10 | |
}); | |
// Read and display the file data on console | |
readStreamfile.on('data', function (chunk) { | |
console.log(chunk); | |
}); | |
// Response as stream | |
readStreamfile.pipe(res); | |
// result of pipe: My name is Mohammad Yaser, I love to share my knowledge | |
}) | |
app.listen(9191, () => { | |
console.log("server run") | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment