WebFund 2014W: Tutorial 9

From Soma-notes

In this tutorial you'll be playing with tinywebserver.js, a static file webserver in node.js that has no dependencies outside of the core node.js modules. It is based on a tiny node.js web server written by Rod Waldhoff. (Note that the original is written in CoffeeScript.)

To run it, just type "node tinywebserver.js". It will begin serving on the web the pages in the same directory as the script. You'll want to have some HTML files to serve; to start off, try serving drawing.html.

Questions

  1. What port is the web server listening on?
  2. What file is returned when you access a directory? Why?
  3. What sort of URL do you give to get the insecure URL warning (403 Forbidden response code)?
  4. What URL do you need to get a 500 error?

Tasks

  1. Change the port the server listens on to be 3000.
  2. Change the server to serve files from /home/student/public_html rather than the current directory. Be sure to put some files in it! (Hint: you can grab HTML files from any webserver using wget.)
  3. Write a minimal node express app that provides the same basic functionality as tinywebserver.js. How big is this program? (To get a fresh express app, you can run "express tiny".) Note that while your app will contain require lines and the corresponding modules, it shouldn't need files outside of those in node_modules (and the static files that are served).
  4. Change tinywebserver.js so it returns a simple HTML error page in response to 404 errors (page not found).