Skip to content

created my 1st back-end application #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions CD220Labs/http_server/index-with-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,22 @@ const today = require('./today');
// Define the request listener function
const requestListener = function (req, res) {
res.writeHead(200); // Set the status code to 200 (OK)
// Send the response with the current date from the 'today' module
res.end(`Hello, World! The date today is ${today.getDate()}`);
let dateVal = today.getDate(); // Get the current date from the 'today' module

// Determine the appropriate greeting based on the current time
let greeting = "It is still not morning";
if (dateVal.getHours() > 6 && dateVal.getHours() < 12) {
greeting = "Good morning!";
} else if (dateVal.getHours() >= 12 && dateVal.getHours() < 18) {
greeting = "Good afternoon!";
} else if (dateVal.getHours() >= 18 && dateVal.getHours() < 21) {
greeting = "Good evening!";
} else if (dateVal.getHours() >= 21 && dateVal.getHours() < 24) {
greeting = "Good night!";
}

// Send the response with the appropriate greeting
res.end(`Hello, ${greeting}`);
};

// Define the port number
Expand All @@ -19,4 +33,4 @@ const server = http.createServer(requestListener);

// Start the server and listen on the specified port
server.listen(port);
console.log('Server listening on port: ' + port);
console.log('Server listening on port: ' + port);
13 changes: 13 additions & 0 deletions CD220Labs/http_server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.