Course Search Page
- Download
- Installation
- Node
- Express
- Routes
- Pug (Template Engine)
- APIs
- Usage
Find the code in https://github.com/sayefiqb/sayefiqbal_cus1172_final repository.
Download the code
Install Node.js on your machine from Node.
Install Express using npm install express.
For better code design use Routes. It helps to register all your routes under a single Routes object. Install Routes using
npm install routes.
Pug is a template engine used to maintain static template files in your application. At runtime, the template engine replaces variables in a template file with actual values passed as parameters from your javascript files, and transforms the template into an HTML file sent to the client which is rendered in the browser. It also keeps your code clean. You must keep your name.pug files in a views folder. Install Pug in your machine using npm npm install pug.
The backend consists of several APIs created using Express and Routes. The data for this project is stored in the sampleData.js file which returns a list of course objects. You can use a database instead and return data as model objects to your javascript file and pass it to your template. Howevrer, for simplicity I used a static sample data file. The following routes are registered using Routes
http://127.0.0.1:3000/courses/qByTitle/:queryTitle/qByName/:queryName/qByInstructor/:queryInstructor
This api endpoint takes the course title, course name and instructor name as possible parameters and then returns filterd search result. You can pass either one, all or none of the parameters. In case of no parameters passed, the api edpoint will return all the json objects from sample data file as results.
http://127.0.0.1:3000/courses/qByLectureType/:query
This api endpoint returns course json objects based on the type of lecture passed as the parameter. The options for this project are lecture, lab and hybrid.
http://127.0.0.1:3000/courses/qBySchedule/:query
This api returns course json objects based on the day of schedule passed as parameter.
http://127.0.0.1:3000/courses/qBySeats
This api endpoint only returns the course json objects which have seats open.
Then open up 127.0.0.1:3000 on your favourite browser.