const stream = fs.createReadStream(filePath, { start, end });
// Handle range requests if (range) { const parts = range.replace(/bytes=/, "").split("-"); const start = parseInt(parts[0], 10); const end = parts[1] ? parseInt(parts[1], 10) : fileSize - 1; const chunksize = (end - start) + 1; video streaming api nodejs
stream.pipe(res); } else { res.writeHead(200, { 'Content-Length': fileSize, 'Content-Type': 'video/mp4', }); fs.createReadStream(filePath).pipe(res); } }); const stream = fs