-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (26 loc) · 766 Bytes
/
server.js
File metadata and controls
29 lines (26 loc) · 766 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
// server.js
const http = require('http');
const fs = require('fs');
const port = 3000;
const server = http.createServer((req, res) => {
// Set the response header
res.writeHead(200, { 'Content-Type': 'text/html' });
// Read the HTML file and serve it
fs.readFile('index.html', (error, data) => {
if (error) {
res.writeHead(404);
res.write('Error: File Not Found');
} else {
res.write(data);
}
res.end();
});
});
server.listen(port, (error) => {
if (error) {
console.log('Something went wrong', error);
} else {
console.log(`Server is listening on port ${port}`);
console.log(`Access the application at: http://localhost:${port}/`);
}
});