From the course: Node.js: Web Servers, Tests, and Deployment

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Creating a file server

Creating a file server

- [Instructor] Now that we understand the basics of creating web servers, let's put those skills to work. We're going to build a little website here using these starter files. We have a homepage, we have a photo, we have some styles, and we have a 404 page. So we're going to need to use our knowledge of HTTP to create a server and we're going to serve up from the file system using the createReadStream function. We're going to use createServer, we're going to use the request and the response, and here we're going to use the switch statement. So given the request URL, if I go to the slash route we want to do something, now what we actually want to do is we want to serve up our HTML file that's in that folder but a nice way to kind of wrap this functionality would be to create a function that takes in the response object, the status, the type of file, and the file name itself and we're going to use all of that data to write…

Contents