-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebFile.txt
More file actions
26 lines (21 loc) · 778 Bytes
/
Copy pathwebFile.txt
File metadata and controls
26 lines (21 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var http = require("http"),
fs = require("fs"),
formidable = require("formidable");
http.createServer((req,res) => {
fs.readFile("template1.html", (err,data) => {
if(req.url == "/fileupload"){
var form = new formidable.IncomingForm();
form.parse(req);
form.on('fileBegin', function (name, file){
file.path = __dirname + '/uploads/' + file.name;
});
form.on('file', function (name, file){
console.log('Uploaded ' + file.name);
});
} else {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
res.end();
}
});
}).listen(8080);