Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
How to add styles to a Node.js readstream.pipe

I have a Node.js backend server, which as soon as it receives a request will create a readstream from the fs module to a video in the films folder, and pipe this to the response.

The browser automatically creates a video tag and streams the film, however, I may wish to add some CSS styles to the video tag, so how would I include some classes or id's on the video before the stream is sent, or is this just not an option?

Code is below:

const getFilm = async (req, res) => {
    let ranges = req.headers.range;
    let film = path.join(__dirname, "..", "films", "IMG_2694.mp4");
    let size = fs.statSync(film).size;
    if(ranges) {
        let [ start, end ] = ranges.replace('bytes=', '').split('-');
        start = parseInt(start, 10);
        end = end ? parseInt(end, 10) : parseInt(size-1, 10);
        res.setHeader('Content-Range', `bytes ${start}-${end}/${size}`);
        res.setHeader('Accept-Ranges', 'bytes');
        res.setHeader('Content-Length', (start - end) +1);
        res.setHeader('Content-Type', 'video/mp4');
        res.statusCode = 206;
        let reader = fs.createReadStream(film, {start, end});
        reader.pipe(res);
    } else {
        res.setHeader('Content-Type', 'video/mp4');
        res.setHeader('Content-Length', size)
        res.statusCode = 200;
        let reader = fs.createReadStream(film);
        reader.pipe(res);
    }
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!