From the course: Advanced Node.js
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Forking and uploading streams - Node.js Tutorial
From the course: Advanced Node.js
Forking and uploading streams
- [Instructor] The HTTP response object is a writable stream and the HTTP request object is a readable stream. We can use the request stream as a source. To get started let's clean up our code a bit. In this lesson our server's gonna handle multiple requests so we're only handling one video request here in range request. What I actually want to do is take all of our code that's inside of this asynchronous handler, and I'm gonna cut the entire function out just by cutting that to the clipboard and I will create a function for this, we'll call it respondWithVideo, so our server still has a little respondWithVideo function, I can just paste the function in. So respondWithVideo is our async function that takes in a request and a response and then goes ahead and sends our one video file that we're loading. So what I'm gonna do is add a new callback handler, so a new function in here, that takes a request and a response. And we're gonna basically check some variables on the request to see…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.