Index
Overview
So far, we've been looking at examples that serve (respond with) simple HTML like "Hello World".
We're going expand our horizons and serve files (specifically their content). Because we're serving to a web browser, we may as well serve HTML content.
We'll combine our acquired file and web server skills.
Guide Examples
These sources will guide you. Simply post to the course discussion board if you don't see the guidance you need.
You will also find "Node.js serve file" as common fodder on the internet.
Problem Statement
Development
- Create a project directory named "serve-file"
- Create two HTML files in the directory tree
- Code a file named "serve-file-1" that "serves" one of the HTML files. In other words, reads it and writes the file content to the response object.
- Code a file named "serve-file-2" that "serves" the other HTML file.
- Use port 3000
- When sending "writeHead", use the "OK" constant from the "http-status-codes" public package as demonstrated in some of the examples (as opposed to hard-coding "200")
Running Programs
Your final program should be usable as follows:
- Start (run) your web server (serve-file-1)
- A web browser opened to host "localhost" and port 3000 should display the HTML content associated with "serve-file-1".
The second program "serve-file-2" should run similarly.
Submit
Code submission/delivery is two step:
- Delete project "node_modules" directory (if present). Here is why...
- Copy project root directory into archive to submit (please do not nest archives)
- Use ".zip" format for archive
Introduction To Node.js
Serve File Drill