Node.js and Express are key building blocks for JavaScript-based web development.

Building an Express Webserver

Start with a basic server.

Exercise 3.1

Implement the hello-world application specified here:

Express (Do the “Getting started”→“Installing” & “Hello world” sections.)

When you have the server running, make sure that you can modify the output text, route and port at will and then answer the following questions.

  1. Compare and contrast the purposes of Node.js and of Express.js.
  2. Explain the purpose of the package.json file.

Save your answers to these questions so that you can add them to your webpage (below).

Note that you should be able to run your server using either of the following commands.

Now, you can serve up some static files.

Exercise 3.2

Configure your server to serve up static files from a public directory, see the “Static files” section of the Express tutorial. When you have it running, serve up a static text file, make sure that you can edit it and see the results, and then answer the following questions.

  1. Explain the sense in which these files are “static”.
  2. Indicate whether the server continues to serve up the hello-world message and explain why this is the case.

Save your answers to these questions so that you can add them to your webpage (below).

Putting It All Together

Serve up a simple webpage that combines HTML, CSS and JavaScript.

Exercise 3.3

Build a webpage that looks something like the example shown on the right. Include at least the following:

See examples of how to integrate these files in the public directory of the GitHub repo for this unit.

Use Chrome DevTools to monitor the browser’s rendering of this webpage. Find out what files are loaded, in what order and how long it took. Note when the message is written to the console log.

Checking in

Submit your solution to GitHub. We will grade your work according to the following criteria: