From 493004b3ed2f7a155f30b9e07e4e9070f893aaa3 Mon Sep 17 00:00:00 2001 From: KubMakCZ Date: Mon, 7 Sep 2026 15:46:27 +0200 Subject: [PATCH] package --- 01_uvod/05.js | 16 +++++++--------- 02_package/index.html | 16 ++++++++++++++++ 02_package/package.json | 18 ++++++++++++++++++ 02_package/server.js | 27 +++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 02_package/index.html create mode 100644 02_package/package.json create mode 100644 02_package/server.js diff --git a/01_uvod/05.js b/01_uvod/05.js index 8d93377..30a2b2f 100644 --- a/01_uvod/05.js +++ b/01_uvod/05.js @@ -1,14 +1,12 @@ -const http = require("http"); +const http = require("http") +const port = 3000 -const port = 3000; - -const server = http.createServer((req,res) => { +const server = http.createServer((req,res)=>{ res.statusCode = 200; - res.setHeader("Content-Type", "text/plain: charset-utf-8"); - - res.end("Ahoj z meho prvního Node.JS serveru!\n"); + res.setHeader("Content-Type","text/plain; charset=utf-8") + res.end("Ahoj z meho prvního NodeJS serveru!\n") }) -server.listen(port, "127.0.0.1", () => { - console.log(`Server beží na adrese http://localhost:${port}`) //AltGR+ý=` +server.listen(port,"127.0.0.1",()=>{ + console.log(`Server běží http://localhost:${port}`)//AltGr+ý=` }) \ No newline at end of file diff --git a/02_package/index.html b/02_package/index.html new file mode 100644 index 0000000..9c23774 --- /dev/null +++ b/02_package/index.html @@ -0,0 +1,16 @@ + + + + + + NODEJS + + +

NodeJS Webserver

+

Lorem ipsum dolor, sit amet consectetur adipisicing elit. Aliquid aut voluptas totam enim illo ex pariatur veniam saepe, ullam officiis dicta quod similique rem est, error nihil corporis facere consequuntur?

+

Blanditiis velit unde nulla ullam, vitae soluta rem earum voluptas expedita provident reprehenderit maiores voluptatum dolor nostrum neque laudantium doloribus officiis consectetur ipsa dolores dignissimos explicabo nihil cum ab. Itaque!

+

Saepe dolores fugiat dolorum rem eos corporis, impedit optio a ipsa officiis molestias praesentium quisquam laboriosam esse libero eaque, ipsum iure. Ipsam neque, illum magnam praesentium reiciendis amet exercitationem distinctio.

+

Quas repellendus, temporibus reprehenderit quis amet reiciendis quae, voluptatem impedit iste et illo? Laboriosam reprehenderit incidunt, autem inventore, labore velit odio cumque vel suscipit officia blanditiis? Odio optio itaque accusamus.

+

Enim perferendis fuga eveniet harum temporibus aliquid eos, quaerat itaque possimus. Repudiandae, ab. Tempora, ab. Labore illum dolorum quo corporis obcaecati laudantium in autem fugit, ratione enim fugiat temporibus molestias?

+ + \ No newline at end of file diff --git a/02_package/package.json b/02_package/package.json new file mode 100644 index 0000000..505d038 --- /dev/null +++ b/02_package/package.json @@ -0,0 +1,18 @@ +{ + "name": "package_01_test", + "version": "1.0.0", + "description": "Malý program na testování NPM balíčků", + "keywords": [ + "test", + "wtl" + ], + "license": "ISC", + "author": "skrabanek", + "type": "commonjs", + "main": "server.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start" : "node server.js 3000", + "startlinux" : "node server.js 8080" + } +} diff --git a/02_package/server.js b/02_package/server.js new file mode 100644 index 0000000..52df16b --- /dev/null +++ b/02_package/server.js @@ -0,0 +1,27 @@ +//import 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) //nalzeneme soubor + const fullPath = path.join(__dirname,filePath) //načteme CELOU cestu + console.log("otevírám:", fullPath) + + fs.readFile(fullPath,(err,content)=>{ + if(err){ + res.writeHead(404,{"content-type":"text/html; charset=utf-8"}) + res.end("

ERROR

Soubor není

") + } 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 bezi http://localhost:${PORT}`) +}) \ No newline at end of file