NodeJS repozitar pro 4.J pro rok 2025/2026
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

27 lines
911 B

//importovat moduly
const http = require("http");
const fs = require("fs");
const path = require("path");
const server = http.createServer((req,res) => {
console.log("REQ:"+req.url);
const filePath = req.url === "/" ? "index.html" : req.url.slice(1)
const fullPath = path.join(__dirname,filePath)
console.log("oteviram:"+fullPath)
fs.readFile(fullPath, (err,content) => {
if(err){
res.writeHead(404, {"Content-type":"text/html"});
res.end("<h1>ERROR</h1> <h2> soubor nenalezen </h2>
<p><a href=\"/\">HOME</a></p> "); // (\") eskejpování uvozovek
} else {
res.writeHead(200, {"Content-type":"text/html"});
res.end(content);
}
})
})
// const PORT = process.argv[2];
const PORT = 3000;
server.listen(PORT,()=> {
console.log(`Server running http://localhost:${PORT} \n Ctrl+C pro vypnutí`);
})