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 30th (after the break).

Lab Objectives

Overview

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 --just ask my Web Enginering students what they had to go through when they were thrown into the fire to use Amazon EC2 (part of the Amazon Web Services family, or AWS for short). For a more elaborate discussion on Heroku vs Amazon AWS, see http://stackoverflow.com/questions/9802259/why-do-people-use-heroku-when-aws-is-present-whats-distinguishing-about-heroku.

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 toolbelt via Homebrew: brew install node mongo heroku-toolbelt.

Software Installation Option 3: For Linux Users

Install Node.js using directions at https://github.com/nodejs/node/wiki. Then, install MongoDB using directions at https://docs.mongodb.org/manual/administration/install-on-linux/. Finally, install Heroku toolbelt.

Important Notes

Instructions, Part I: Preliminaries

  1. Create a Heroku account: https://www.heroku.com/ (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 https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction 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: https://github.com/heroku/node-js-getting-started

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, https://defense-in-derpth.herokuapp.com/submit, 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 point 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 /submit: {"vehicles":[],"passengers":[]} (that is, a hard-coded JSON with two keys: vehicles and passengers and the values to each is an empty list).

Accessing https://[YOUR_APP_IDENTIFIER_RANDOMLY_GENERATED].herokuapp.com/submit 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].herokuapp.com/submit), the JSON string above will be the response.

Important: Cross-Origin Resource Sharing must be enabled for POST /submit.

Once you have completed this, change the URL https://defense-in-depth.herokuapp.com/submit to https://NAMEOFYOURHEROKUAPP.herokuapp.com/submit in your Assignment 2 and your map should work with no errors in the JavaScript console. If your Assignment 2 map does not work, or if JavaScript changes are required to your previous work, then something is wrong with your server. Important: DO NOT PUSH this URL change for your Assignment 2 to your private GitHub repository as we may be still grading Assignment 2!

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.

The README File

Modify the README.md 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".

Assessment