Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Step 1: Create the following directory structure public - this is the application root directory assets - this directory includes static resources and supporting files
Step 1:
- Create the following directory structure
- public - this is the application root directory
- assets - this directory includes static resources and supporting files (CSS, images,...) that can are publicly accessible
- images - directory for storing application images
- stylesheets - directory for storing stylesheet files
- views - this directory should contain files used for client view
- routes - this directory should contain files related to request/response handling and route control
- models - this directory should contain files related to data object
Step 2:
- Create and export a Course class (Course.js) in the models directory that represents a course model with the following properties:
- CourseID
- Title
- Term
- Instructor
Step 3:
- Create View files
- details.ejs - this file has the following requirements
- render to a valid html page
- if course data is available display a table that showing a course details and displays a course number, title, term and instructor.
- if no course data is available display a default message (e.g, "No course details available!")
- displays an image by including image.ejs
- references an external stylesheet to set table properties (see next step)
- image.ejs - this file should contain code snippet (partial) that will display a default image available under the images directory
- save these files under the views directory
- details.ejs - this file has the following requirements
Step 4:
- Create the external stylesheet file and save it under the assets/styles directory. This file should include style information at a minimum it should set the background color of the table to #F1948A and text font color to #78281F
Step 5:
- Create route handling -
- courseDetails.js file in the routes directory
- loads the express module and uses it to get an express.Router object.
- specifies the route handlers for the application route "/coursedetails"
- the root for this route (router.get('/',...))
-
- should check for request parameters
- if no parameters are passed as a part of the request the response should be rendered by details.ejs displaying a default message.
- be simple text indicating no information available or requested. (query or param)
- if course info is sent as request parameters (for example using the url /coursedetails?courseID=1212&title=CS1&term=spring2020&instructor=najjar) the response should be rendered by details.ejs displaying the course details.
- note: you must create a course model (object) that is defined in course.js and send that object to the view for display
- should check for request parameters
- exports the router from the module.
- index.js file in the routes directory
- loads the express module and uses it to get an express.Router object.
- specifies the route handlers for the application root route that responds with a plain text message (e.g, "Welcome to the course app!")
- lastly exports the router from the module.
- courseDetails.js file in the routes directory
Step 6:
- Create the main configuration file for the application - app.js. This file should be under the application root directory and does the following:
- create the app object using an imported express module
- set up the view (template) engine (in our case we are using "ejs")
- import and use the express.static middleware to get Express to serve all the static files in the assets directory in the project root.
- import the route-handling files and add it to the request handling chain. The imported code will define particular routes for the different parts of the application:
- /coursedetails -
- uses the route handlers defined in courseDetails.js
- / and /*
- uses the route handler defined in index.js
- /coursedetails -
- import the route-handling files and add it to the request handling chain. The imported code will define particular routes for the different parts of the application:
- creates a server listening for HTTP requests on port 8084
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started