Closed Pomog closed 7 months ago
@Pomog, could you please share the error you're getting? :)
Error: Already failed code at commit bcadcbf
Previous output: timeout: Did you write an infinite loop?
<html>
<body>
<!--StartFragment-->
import http from "http";
--
| import fs from "fs";
|
| const PORT = 5000;
| const GUESTS_DIRECTORY = "./guests/";
| // const GUESTS_DIRECTORY = "./";
|
| const server = http.createServer((req, res) => {
| console.log(`Server listening on port ${PORT}`);
|
| // Extract guest name from request URL
| const guestName = req.url.substring(1); // Remove leading '/'
|
| // Read guest JSON file
| fs.readFile(`${GUESTS_DIRECTORY}${guestName}.json`, "utf8", (err, data) => {
| // fs.readFile(`}${guestName}.json`, "utf8", (err, data) => {
| if (err) {
| if (err.code === "ENOENT") {
| // Guest not found
| res.writeHead(404, { "Content-Type": "application/json" });
| res.end(JSON.stringify({ error: "guest not found" }));
| } else {
| // Server error
| res.writeHead(500, { "Content-Type": "application/json" });
| res.end(JSON.stringify({ error: "server failed" }));
| }
| } else {
| // Send guest details
| res.writeHead(200, { "Content-Type": "application/json" });
| res.end(data);
| }
| });
| });
|
| server.listen(PORT);
<!--EndFragment-->
</body>
</html>
- It has to listen on port
5000
, and it will have to print a simple message on the console, specifying the listening port;
Your solution looks fine, but you should check this point. I will add a small change to clarify: the message should be displayed as soon as it starts (if not it means you already know which port the server is listening to ;)
thanks, solved
server.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
});
confusing task
thanks
friend-support There is an Error with tests Because this code works