In this exercise, you'll use the fs
module and the http
module to create an HTTP file server.
- Fork and clone this repository. A skeleton server has been defined for you in
server.js
and should serve as the basis for your application. - Start your server with the command
node server.js
.
- Open a browser to localhost:8000.
- You should see the greeting, "Hello, World!"
- Add code inside of
handleRequest
that will display the phrase "I can change the response." - Open a browser to localhost:8000 and view the updated text.
- Add a file named
about.html
to your repository. - Add inside of
about.html
the text "I'm a response inside of a file!" - Require the
fs
module inside ofserver.js
- Use the
fs
module to serveabout.html
when visitinghttp://localhost:8000/about.html
. - Repeat what you did with
about.html
and do the same for a file namedfaq.html
.
- Add an anchor tags that connect both pages.
about.html
, for instance, should include a link tofaq.html
and vice versa. - Create a third page named
index.html
. This page should include anchor tags toabout.html
andfaq.html
. - Serve
index.html
when visitinghttp://localhost:1337
- Add CSS to all pages.
- Create a
404 Not Found
page for any route that's not/
,/about.html
, or/faq.html
. You could use an appropriate image from cat status codes. - Refactor your code to find a general way to handle requests for all files in this directory. For instance, remove the routes from
server.js
and place them in a file namedroutes.js
.