I am currently in the process of creating a to-do list using an older tutorial. The app.js file seems to be functioning properly, however, when I try to run it locally, all I see is a blank page instead of my HTML content.
Here is the code found in the app.js file:
const express = require('express');
const app = express();
app.use(express.urlencoded({
extended: true
}));
app.use(express.json())
app.get("/", function (req, res) {
let today = new Date();
if (today.getDay() === 0) {
res.write("<h1>Yay It's the weekend</h1>");
} else {
res.sendFile(__dirname + "todolist-v1\index.html");
}
res.send();
});
app.listen(3000, function () {
console.log(`App listening on port ${3000}`)
});
As for the index.html file, here is its content:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>To Do List</title>
</head>
<body>
<h1>This does not seem to be working!</h1>
<p>Why isn't this loading!?</p;
<script src="app.js"></script>
</body>
</html>
I was hoping that when accessing localhost, the index.html file would be displayed, but instead, only the app.js seems to appear.