2022-01-20
1604
#node
Samuel Martins
87908
Jan 20, 2022 â‹… 5 min read

Build a video streaming server with Node.js

Samuel Martins I am a full-stack developer who loves sharing the knowledge accumulated over the years with people. The different technologies that I have encountered through my journey allows me to relate to beginners and seniors alike. I write about all things tech.

Recent posts:

Vue logo over a brown background.

A guide to two-way binding in Vue

Learn how to implement one-way and two-way data binding in Vue.js, using v-model and advanced techniques like defineModel for better apps.

David Omotayo
Nov 22, 2024 â‹… 10 min read
TypeScript logo over a pink and white background.

Drizzle vs. Prisma: Which ORM is best for your project?

Compare Prisma and Drizzle ORMs to learn their differences, strengths, and weaknesses for data access and migrations.

Temitope Oyedele
Nov 21, 2024 â‹… 10 min read
Practical Implementation Of The Rule Of Least Power For Developers

Practical implementation of the Rule of Least Power for developers

It’s easy for devs to default to JavaScript to fix every problem. Let’s use the RoLP to find simpler alternatives with HTML and CSS.

Timonwa Akintokun
Nov 21, 2024 â‹… 8 min read
Rust logo over black marble background.

Handling memory leaks in Rust

Learn how to manage memory leaks in Rust, avoid unsafe behavior, and use tools like weak references to ensure efficient programs.

Ukeje Goodness
Nov 20, 2024 â‹… 4 min read
View all posts

10 Replies to "Build a video streaming server with Node.js"

  1. But `express.static()` supports ranged requests out of the box.

    Looks like all you needed was a middleware that rejects non-ranged requests, although that detail seems a bit questionable, as not all browsers use ranged requests to play video.

    (If this was intended as just an exercise, the article probably should explain that.)

  2. Not sure but I I think that if you put a `return` under `res.status(400).send(“Requires Range header”);` you can avoid this error that I get“`Cannot read properties of undefined (reading ‘replace’)
    Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client“` when I try to access directly `/video`

  3. i have try but in mobile client it is not work that use video to receive stream, Is any body else face the same issue like me

  4. Is there a way to stream a camera link (cctv) or network stream (droidcam) instead of a fixed video.

  5. I would like to serve a 10 second .mp4 video, and after the stream completes, I would like to redirect to a static html page. Problem I get is that when video completes, I can’t figure out how to then serve the .html file. I’m trying to do this with the Express package. Is there a way for one node.js file server to serve a .mp4 file then an .html file?

    1. Yes you can use event emitter and emit the ‘end’ event where you can redirect the user to html file.

  6. Really helpfull, thanks for sharing. You should run it as https server since http is not really used anymore.

    /* your CONSTs block */
    // https server CONSTs
    const privateKey = fs.readFileSync(‘path/to/your_key_file.ext’, ‘utf8’);
    const certificate = fs.readFileSync(‘path/to/your_cert_file.ext’, ‘utf8’);
    const credentials = {key: privateKey, cert: certificate};
    const https = require(‘https’);
    const port = process.env.PORT || 8443;

    /* your app.get() blocks */

    var httpsServer = https.createServer(credentials, app);

    httpsServer.listen(port, function () {
    console.log(“Listening on port ” + port + “!”);
    });

Leave a Reply