#codewithsumit #nodejs #nodejstutorial
In this video we are going to create a video streaming server from scratch.
We will code a streaming server with help of express framework.
Following is the link to install express:
https://www.npmjs.com/package/express
nodejs and express js tutorial
https://bit.ly/3a5cpgc
Express tutorial in Hindi playlist
• Express JS Tutorial in Hindi | Learn Expre...
#express #expressjs #nodejs #node #nodejstutorial #trandingcomedy #tranding #funnyvideo #tutorial #nodejshindi #nodejstutorial #javascript #programming #restapis #nodejs and express js tutorial
Content of index.js
=======================
const express = require('express');
const app = express();
const fs = require('fs');
app.get('/', function(req, res){
res.sendFile(__dirname+ "/index.html");
})
app.get('/video', function(req, res){
const range = req.headers.range;
if(!range){
res.status(400).send("Requires Range header");
}
const videoPath = "./tom&jerry.mp4";
const videoSize = fs.statSync(videoPath).size;
// console.log("size of video is:", videoSize);
const CHUNK_SIZE = 10**6; //1 MB
const start = Number(range.replace(/\D/g, ""));
const end = Math.min(start + CHUNK_SIZE , videoSize-1);
const contentLength = end-start+1;
const headers = {
"Content-Range": `bytes ${start}-${end}/${videoSize}`,
"Accept-Ranges": 'bytes',
"Content-Length": contentLength,
"Content-Type": "video/mp4"
}
res.writeHead(206,headers);
const videoStream = fs.createReadStream(videoPath,{start, end});
videoStream.pipe(res);
})
app.listen(3000, function(){
console.log("Server is running on port:", 3000);
})
On this page of the site you can watch the video online NodeJS Tutorials in Hindi: Create Video Streaming Server in Node.js | Streaming Application in Node with a duration of hours minute second in good quality, which was uploaded by the user CodeWithSumit 16 July 2022, share the link with friends and acquaintances, this video has already been watched 14,421 times on youtube and it was liked by 340 viewers. Enjoy your viewing!