Skip to content

Instantly share code, notes, and snippets.

@myas92
Last active August 3, 2022 09:32
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 myas92/f90261a9aace3c1e571a8bc7d0c71d24 to your computer and use it in GitHub Desktop.
Save myas92/f90261a9aace3c1e571a8bc7d0c71d24 to your computer and use it in GitHub Desktop.
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