WebFund 2014W: Tutorial 9
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.
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
- What port is the web server listening on?
- What file is returned when you access a directory? Why?
- What sort of URL do you give to get the insecure URL warning (403 Forbidden response code)?
- What URL do you need to get a 500 error?
Tasks
- Change the port the server listens on to be 3000.
- 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.)
- 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).
- Change tinywebserver.js so it returns a simple HTML error page in response to 404 errors (page not found).