Body: I am developing a simple Node.js application using Express. My goal is to serve an HTML file located in the views folder, but when I access the page, it shows a blank screen without any content.
Code:
const express = require('express');
const path = require('path');
const app = express();
const port = 3000;
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'views', 'index.html'));
});
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});
HTML File (views/index.html):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Page</title>
</head>
<body>
<h1>Hello World!</h1>
<p>This is a test page.</p>
</body>
</html>
Error Messages: I do not see any error messages in the terminal or the browser console.
What I’ve Tried:
I ensured that the server is running and that I can access http://localhost:3000/.
I checked the file paths to ensure they are correct.
I tried using a simple HTML file to see if it renders anything.
I am using Windows 10 (Crack Version) and wondering if it might affect the application.
Expected vs. Actual Behavior:
Expected: The browser should display “Hello World!” and the text “This is a test page.”
Actual: The page is blank with no content displayed.
Environment:
OS: Windows 10 (Crack Version)
Node.js version: 20.17.0
Express version: 4.21.1