6 changed files with 113 additions and 0 deletions
@ -0,0 +1,36 @@ |
|||||
|
//npm instal formidable@1.2.2
|
||||
|
|
||||
|
var http = require("http"); |
||||
|
var formidable = require("formidable"); |
||||
|
var fs = require("fs"); |
||||
|
var path = require("path"); |
||||
|
|
||||
|
http.createServer(function (req,res) { |
||||
|
if (req.url == "/fileupload") { |
||||
|
var form = new formidable.IncomingForm(); |
||||
|
form.parse(req, function (err,fields,files){ |
||||
|
var oldpath = files.filetoupload.path; |
||||
|
var newpath = path.join(__dirname,"uploads",files.filetoupload.name); |
||||
|
console.log(oldpath); |
||||
|
console.log(newpath); |
||||
|
fs.rename(oldpath,newpath, function (err) { |
||||
|
if (err){ |
||||
|
console.log(err); |
||||
|
res.writeHead(200,{"content-type":"text/plain"}); |
||||
|
res.end("ISE") |
||||
|
return; |
||||
|
} |
||||
|
res.write("File uploaded"); |
||||
|
res.end(); |
||||
|
}) |
||||
|
}) |
||||
|
} else { |
||||
|
res.writeHead(200, {"Content-type":"text/html"}); |
||||
|
res.write('<form action="fileupload" method="post" enctype="multipart/form-data">'); |
||||
|
res.write('<input type="file" name="filetoupload"><br>'); |
||||
|
res.write('<input type="submit">'); |
||||
|
res.write('</form>'); |
||||
|
return res.end() |
||||
|
} |
||||
|
}).listen(8080) |
||||
|
console.log("Server bezi na http://localhost:8080" ); |
@ -0,0 +1,42 @@ |
|||||
|
{ |
||||
|
"name": "webserver_v3", |
||||
|
"version": "3.2.1", |
||||
|
"lockfileVersion": 3, |
||||
|
"requires": true, |
||||
|
"packages": { |
||||
|
"": { |
||||
|
"name": "webserver_v3", |
||||
|
"version": "3.2.1", |
||||
|
"license": "ISC", |
||||
|
"dependencies": { |
||||
|
"formidable": "^1.2.2", |
||||
|
"upper-case": "^2.0.2" |
||||
|
} |
||||
|
}, |
||||
|
"node_modules/formidable": { |
||||
|
"version": "1.2.2", |
||||
|
"resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.2.tgz", |
||||
|
"integrity": "sha512-V8gLm+41I/8kguQ4/o1D3RIHRmhYFG4pnNyonvua+40rqcEmT4+V71yaZ3B457xbbgCsCfjSPi65u/W6vK1U5Q==", |
||||
|
"deprecated": "Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau", |
||||
|
"license": "MIT", |
||||
|
"funding": { |
||||
|
"url": "https://ko-fi.com/tunnckoCore/commissions" |
||||
|
} |
||||
|
}, |
||||
|
"node_modules/tslib": { |
||||
|
"version": "2.7.0", |
||||
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", |
||||
|
"integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==", |
||||
|
"license": "0BSD" |
||||
|
}, |
||||
|
"node_modules/upper-case": { |
||||
|
"version": "2.0.2", |
||||
|
"resolved": "https://registry.npmjs.org/upper-case/-/upper-case-2.0.2.tgz", |
||||
|
"integrity": "sha512-KgdgDGJt2TpuwBUIjgG6lzw2GWFRCW9Qkfkiv0DxqHHLYJHmtmdUIKcZd8rHgFSjopVTlw6ggzCm1b8MFQwikg==", |
||||
|
"license": "MIT", |
||||
|
"dependencies": { |
||||
|
"tslib": "^2.0.3" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
{ |
||||
|
"name": "webserver_v3", |
||||
|
"version": "3.2.1", |
||||
|
"description": "Maly webserver", |
||||
|
"main": "index.js", |
||||
|
"scripts": { |
||||
|
"test": "node tester.js 25525" |
||||
|
}, |
||||
|
"author": "KubMakCZ", |
||||
|
"license": "ISC", |
||||
|
"dependencies": { |
||||
|
"formidable": "^1.2.2", |
||||
|
"upper-case": "^2.0.2" |
||||
|
} |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
var http = require("http"); |
||||
|
var uc = require("upper-case"); |
||||
|
// npm install upper-case@2.0.2 <- ninstalovat knihovnu
|
||||
|
|
||||
|
var PORT = process.argv[2] || 8080; |
||||
|
|
||||
|
if(!process.argv[2]) { |
||||
|
console.log ("nebyl zadaný port, použije se výchozí 8080"); |
||||
|
} |
||||
|
|
||||
|
http.createServer(function (req,res) { |
||||
|
res.writeHead(200, {"content-type":"text/html"}); |
||||
|
res.write(uc.upperCase("HeLLo WoRLd")); |
||||
|
res.end(); |
||||
|
}).listen(PORT); |
||||
|
|
||||
|
console.log("Server bezi na http://localhost:" + PORT); |
||||
|
|
||||
|
//npm run test
|
||||
|
//http://localhost:8080/
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue