libcasa-chan/server.js
2023-01-26 18:55:29 -05:00

25 lines
513 B
JavaScript

const http = require("http");
const fs = require("fs");
const server = http.createServer((req, res) => {
if (req.url === "/") {
res.statusCode = 200;
res.setHeader("Content-Type", "text/html");
fs.readFile("index.html", function(error, data) {
if (error) {
res.writeHead(404);
res.write("Error: File not found.");
} else {
res.write(data);
}
res.end();
})
}
})
const port = process.env.port || 8000;
server.listen(port, () => console.log(`Server running on port ${port}`));