//npm install 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.error(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);