//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('
'); res.write('
'); res.write(''); res.write('
'); return res.end() } }).listen(8080) console.log("Server bezi na http://localhost:8080" );