Youtube video streaming through Node.js server

I am trying to create a simple web server in Node.js that will call the Youtube video API to receive the video and transfer it to the client (after some checks, but this does not bother me at the moment), since it extracts it from Youtube.

To start, I try to do this in two parts, download and save to disk, and then place it from disk. Although I can transfer the file from disk to the client, I could not download and save part of the work. Here is the code for this

var request = require('request'); var http = require('http'); var fs = require('fs'); http.createServer(function(req,res) { request('http://www.youtube.com/embed/XGSy3_Czz8k').pipe(fs.createWriteStream('testvideo.mp4')); }).listen(80, '127.0.0.1'); console.log('Server running at http://127.0.0.1:80/'); 

I thought the request module could just pass the output to a file. Can someone please suggest what I am doing wrong here?

Any directions on how to get YouTube videos and stream simultaneously to the client while the video is being retrieved from youtube?

+4
source share
1 answer

I tried to do this and it works.

 var request = require('request'); var http = require('http'); var fs = require('fs'); http.createServer(function(req,res) { var x = request('http://www.youtube.com/embed/XGSy3_Czz8k') req.pipe(x) x.pipe(res) }).listen(1337, '127.0.0.1'); console.log('Server running at http://127.0.0.1:1337/'); 
+6
source

All Articles