-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (26 loc) · 745 Bytes
/
index.js
File metadata and controls
30 lines (26 loc) · 745 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
const http = require('http');
const fs = require('fs');
const path = require('path');
const port = process.env.PORT || 3000;
const server = http.createServer((req, res) => {
if (req.url === '/') {
// Serve the index.html file
const filePath = path.join(__dirname, 'index.html');
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
res.writeHead(500);
res.end('Error loading the page');
} else {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(data);
}
});
} else {
// Handle 404 - Not Found
res.writeHead(404);
res.end('Page not found');
}
});
server.listen(port, () => {
console.log(`Server running on http://localhost:${port}/`);
});