These exercises are meant to help students get started on a particular technology. The work will not be collected, nor graded. However students are strongly encouraged to complete these exercises because these exercises will help our projects.
Please read and try out the code examples in various directories under the code example directory. You are to modify these programming examples to complete the exercises. You should read the original tutorial quoted in the code examples as needed because more information is available in those tutorials.
A number of tutorials on the web are very helpful in learning these concepts. Please consult the course resource page for references.
If you find any Node package is missing, you can install it using the Node Package Management tool, as follows.
npm install [packet-name]
npm install express
will install the express package in your directory.
- Simple web server: Read the programs, webserver.js, understand what and how the program works. Then do the following.
- Run the server program as
- Open a browser, access the server you just started using the following URLs, one at a time
where host is the name of the computer on which your server is running
What are the responses you see on the browser? Make sure you understand where and how these responses were generated by your server. In particular when the server sends the
form.htmlpage, type some information into the form and hit
Submitto see what happens. Why?
- Create a sub-directory below the directory where the server program is called public. In the public directory, you can put a few files for public to access. You could copy the files in this sample public directory to serve the purpose. Try to make the pages look beautiful and professional.
- Read the run the program file-stats.js
node file-stats.js form.html
form.html here is just an example, it can be any files or directories.
- Modify the program webserver.js using the structure in file-stats.js such that only files that are readable by the public (all) can be accessed by the browser. If the file or directory requested is not accessible by the public, an error message along with HTTP code 403 should be generated.
- Simple web client: Read and understand the program webclient.js. Then do the following.
node webclient.js www.eg.bucknell.edu 80 /~cs479/index.html
The command above directs the web client to access our course web page served by host www.eg.bucknell.edu at the default port 80.
With webserver.js running as in the previous exercise, try
node webclient.js localhost 8081 /home.html
node webclient.js www.cnn.com 80 /
Make sure you understand the flow of information.
- The Express package: While Node.js provides many easy-to-use features that support web application, Express is a flexible and minimum Node.js framework that specializes in web applications.
Read and understand the program express-server.js. Then do the following.
- Run the program as
The command above runs an Express server on the local host that is ready to take requests.
- In a browser, try with the following URLs, one at a time
Make sure you understand the flow of information.
- Revise the program such that when the URL issued to the browser is the root of the web site, as in
the server will return the form that was seen in form.html and the server can still process the input as usual.
- AngularJS While Node.js provides framework for web based programming, AngularJS is mainly used for building web pages. See the course resource page for tutorials on the subject. Here is a simple page that is written in AngularJS. You can study the page (by viewing the page source) and see various elements of AngularJS.
- MongoDB You can look for general information about MongoDB on the internet very easily. Here we provide a few points of using MongoDB in the Bucknell environment and Python support for MongoDB.
- The tutorial for MongoDB provided by TutorialPoint is a very good starting point to learn the basics of mongodb.
- To use MongoDB a server has to be running on a computer. You may find some publicly available mongodb servers on the internet. Bucknell runs its own server, similar to its mysql server.
- A student must request a database under mongo from the system administrator. See this AskLIT article for details. CSCI 479 students have been an account (a database).
- One can connect to the database following the instructions provided by the above AskLIT article with proper credentials. Once connected, you can issue database commands to perform various operations. This file contains some of the mongodb commands that I have tried in my database.
- Python connection: A general programming language such as Python provides functions that allow the users to manipulate mongodb database in the same way as any other databases such as mySQL. In this code example directory, you will see a few Python programs that work with mongodb databases. Please refer to the resource page for more links to other information regarding mongodb and Python connection to it.
- Look at this file for some comparison between MongoDB (non-relational database or noSQL database) with relational databases.