Once you set up a web server, you likely want to use it to serve files. In this video, help Alex Banks construct his profile website by building a file server that can serve HTML, CSS, and JPEG images.
of creating web servers, let's put those skills to work. … We need to build a web server … that can handle serving some files. … that will make more requests … for more files on my web server. … Take a look at the home-page.html. … And then, I'm also going to destructure the createReadStream … function from the FS module. … This function's going to take in the response stream, … Or actually, the file path for the file that we're sending. … So, res.writeHead can be used to create the header. … Now previously, we've been sending … the status directly to this function. … We're going to send the status from our arguments. … So, every time we send a file … or every time we invoke this function, … So, the next thing we need to do is supply the headers. … for the file in our local folder that we want to read. … So, once we create this readable stream, … my response object, the status at 200, … and then the path to our file, ./alex-banks.jpeg. … is going to be return … using this reusable sendFile function that we created. …
- Making HTTP requests
- Building web and file servers
- Installing packages with npm
- Managing and linking global packages
- Working with Express, the web server framework
- Handling POST and DELETE requests
- Creating WebSockets
- Testing and debugging Node.js code
Skill Level Advanced
Node.js: Real-Time Web with Socket.IOwith Emmanuel Henri1h 24m Intermediate
Work with VSCode1m 59s
1. The HTTP Module
3. Web Servers
5. Node.js Testing
6. Automation and Deployment
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.