COMP 20: Web Programming

Lab: The Server Side using Node.js and Heroku

This lab is worth 3 points.

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 may be using a database in part 3 of the ride-hailing service lab, 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 part 2 of the ride-hailing service lab, I provided a URL to send data to and in return, receive data on nearby vehicles,, a HTTP POST route. I will be decommissioning this resource after the lab is graded. Therefore, your map will no longer work. To make your map work again, you must recreate the server-side, the purpose of part 3 of the ride-hailing service lab.

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 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 https://[YOUR_APP_IDENTIFIER_RANDOMLY_GENERATED] in your ride-hailing service lab and your map should work with no errors in the JavaScript console. Important Note: you will encounter an error in the JavaScript console of your web browser when you load your map.........

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 part 3 of the ride-hailing service lab. If you want to start a new repository on Heroku for part 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 lab.
  3. Say approximately how many hours you have spent completing the lab.

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".