-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (29 loc) · 1020 Bytes
/
app.js
File metadata and controls
32 lines (29 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const http = require('http');
const fs = require('fs');
const path = require('path');
const server = http.createServer((req, res) => {
// Check if the request is for a specific URL, for example, '/WebPage/homePage.html'
if (req.url === '/WebPage/homePage.html') {
// Build the full file path
const filePath = path.join(__dirname, 'WebPage', 'homePage.html');
// Read the content of the HTML file
fs.readFile(filePath, (err, data) => {
if (err) {
// Handle any errors, such as the file not being found
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('File not found');
} else {
// Send the HTML content as the response
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(data);
}
});
} else {
// Handle other requests or URLs
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('Not Found');
}
});
server.listen(3000, () => {
console.log('Server is running on port 3000');
});