Pset 2: Node.js

The goal of this pset is to learn Node.js and it’s Express web server. You will adapt your pset 1 implementation so the client’s requests get routed to your own server. Your server, will forward the requests to the Harvard Art Museums API, and relay the responses back to the client. While this is strictly more complicated than the way you handled queries in pset 1, it allows you to keep your art museum API key secret and, in a future pset, will allow you to store interesting user history and preferences (such as a users’ favorite objects) in a database. It also allows you to get familiar with Node.js, which is indispensable for larger frameworks such as vue.

For background on Node, see the wiki page.

Ground Rules

Installing Node.js

Node.js is already installed on in ide50. You get the added advantage that you can fire up your Express application, close the ide50 tab in your browser, and it will keep running.

If you don’t want to use ide50, you can install Node.js on linux via your package manager, on Mac via Homebrew or MacPorts, or on any platform by following the instructions at There is no need for the latest, greatest version–8.12.0 or newer is fine–but make sure you install npm as well.

Learning Node.js

Start with the learnyounode tutorial, through the “Make It Modular” lesson. The HTTP sections of the tutorial are superceded by Express. Keep in mind that learnyounode uses old-style Javascript; you should use let instead of var, not to mention arrow functions and all the other nifty ES2015 goodies.

Continue with Robbie Jaeger’s Introduction to Node’s Express JS, and the Express’s own (Getting Started)[] pages. (Getting started is its own menu in the navbar, with several subsections.) If you are using ide50, you may need to change the port in the app.listen() call to 8080 or something similar.

Debugging Node.js

The easiest way to debug your Node.js code is through Chrome. See the Debugging Guide for instructions. If you are developing on ide50, you may need to bind the debugger to instead of the default

Useful Node.js Modules

In addition to Express, you’ll need some additional modules: