COMP 20: Web Programming

Lab: The Server Side using Node.js and Heroku

This lab is worth 3 points. This lab is due on Thursday, March 28th (after the break).

Lab Objectives


Server-side development is more involved than what we have been doing so far and requires a number of components and software including Node.js and MongoDB (database). You will be using a database in Assignment 3 but not in this lab.

For this class, we will deploy our server-side web application to Heroku. Why use Heroku you may ask? With Heroku, we do not need to worry about the server hardware, server configuration, and server maintenance. Server configuration and maintenance require an extraodinary amount of work. For a more elaborate discussion on Heroku vs Amazon AWS, see

Software Installation Option 1 (required for Windows):

Use the virtual machine (VM). You will also need to install the Heroku toolbelt on the VM on your own.

Software Installation Option 2: For Advanced Mac OS X Users

If you are a Mac user and choose not to use a virtual machine, install Node.js, Mongo DB, and the Heroku CLI (Command Line Interface) via Homebrew:

Software Installation Option 3: For Linux Users

Install Node.js using directions at Then, install MongoDB using directions at Finally, install Heroku CLI.

Important Notes

Instructions, Part I: Preliminaries

  1. Create a Heroku account: (free)
  2. In order to use MongoDB via addon in a web application on Heroku, you will need to verify your Heroku account via of a credit card. You will not be billed. The reason for this is to verify that you are a human, and not a spammer. If you do not have a credit card or not comfortable with using one, an alternative option is to buy and use prepaid credit card.
  3. Follow the instructions at up to and including the "Provision add-ons" section. IMPORTANT: Be careful in the "Scale the app" section. I suggest you skip the section because if you are not careful, you will be billed and we will not be responsible for your actions!
  4. Please read the README for the node-js-getting-started example on GitHub:

Instructions, Part II: Sending Data To and Serving JSON Data

In Assignment 2, I provided a URL to send data to and in return, receive data on nearby passengers or vehicles,, a HTTP POST route. I will be decommissioning this resource after Assignment 2 is graded. Therefore, your map in Assignment 2 will no longer work. To make your map work again, you must recreate the server-side, the purpose of Assignment 3.

Modify index.js in your node-js-getting-started so that it serves the following JSON when one accesses the route via POST /rides, the following is returned as the response:


(that is, a hard-coded JSON with one key: vehicles, and the value is an empty list)

Accessing https://[YOUR_APP_IDENTIFIER_RANDOMLY_GENERATED] on a web browser will not work (recall Quiz 1 and how web browsers work). However, if you make an HTTP POST request via curl and send it any data, anything (e.g., curl --data "username=whocares" https://[YOUR_APP_IDENTIFIER_RANDOMLY_GENERATED], the JSON string above will be the response.

Once you have completed this, change the URL to in your Assignment 2 and your map should work with no errors in the JavaScript console. Important: Cross-Origin Resource Sharing must be enabled for POST /rides in order for this to work. If your Assignment 2 map does not work (i.e., errors exist in JavaScript console of your web browser), or if JavaScript changes are required to your previous work, then something is wrong with your server.

For this part of the lab, you are allowed to use additional Node.js modules although you really do not need to. You are strongly urged to continue building upon node-js-getting-started for your Assignment 3. If you want to start a new repository on Heroku for your Assignment 3, you will also need to add me as a collaborator for that new Heroku app.


Modify the file in node-js-getting-started that describes your modifications. This description must:

  1. Identify what aspects of the work have been correctly implemented and what have not.
  2. Identify anyone with whom you have collaborated or discussed the assignment.
  3. Say approximately how many hours you have spent completing the assignment.

Submitting the Lab

Add me as a collaborator (using my email address mchow[AT]cs[DOT]tufts[DOT]edu) for your web application in Heroku. You can do this by logging on to Heroku, go to the dashboard for your web application, under "Access", click on the "Add collaborator" button, enter my email address, and click "Save changes".