Question
Build a dynamic website using Node.js with Express.js and Pug.js. For this assignment, pick a country and build a brochure website (ie a one page
Build a dynamic website using Node.js with Express.js and Pug.js. For this assignment, pick a country and build a brochure website (ie a one page website with information), all facts listed on the page can be made up and the content needs to be G or PG. This website will change based on the system time of the machine running Node.js. If the user views the page from 7 am to 7 pm (inclusive), the page should have a CSS and look based around day. The facts about that country should be day oriented. If the page is viewed outside of 7 am to 7 pm, the facts and CSS theme should change to be night oriented. The majority of the pages look and information should change based on being day or night.
Also, your page must accept a query parameter called hour that will instead use that time instead of the system time. The hour must be able to be input as military time (ie 1 is 1 am and 13 is 1 pm).
'use strict';
const express = require('express'),
app = express();
app.set('view engine', 'pug');
app.set('views', 'views');
app.use(express.static('resources'));
app.get('/', function (req, res) {
let date = new Date();
let time = date.getHours();
if (time >= 7 && time <= 18) {
res.render('day');
}
else {
res.render('night');
}
});
app.get('/hour', function(req, res){
const hour = req.query.hour;
if(hour >=7 && hour <= 19){
res.render('day');
}
else {
res.render('night');
}
});
const server = app.listen(3000, function(){
console.log(`Server started on port ${server.address().port}`);
});
Above is a copy of my code with the pug files being named 'day' and 'night'. I have pretty much completed this assignment, but am having one issue that I cannot seem to figure out. The base path for the page is localhost:3000/ and the base path with the query parameter, hour, is supposed to be localhost:3000/?hour=(hour). The only way I can get the program to run correctly is by using the path localhost:3000/hour?hour=(hour). What is a good way to write this so I can get the expected results with using the path of localhost:3000/?hour=(hour)?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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