var http = require (‘http’);
var formidable = require (‘formidable’);
var fs = require (‘fs’);

http.createServer (function (req, res) {
if (req.url == '/ upload') {
var form = new formidable.IncomingForm ();
form.parse ( req, function (err, fields, files) {
var oldpath = files.filetoupload.path; // ตำแหน่ง ที่ เรา เลือก ต้นทาง
var newpath = 'uploads /' + files.filetoupload.name; / / ตำแหน่ง ปลายทาง
fs.rename (oldpath, newpath, function (err) {
if (err) throw err;
res.write ('Upload Complete!');
res.end ();
});
});
} else {
res.writeHead (200, {'Content-Type': 'text / html'} );
res.write ('‹form action =" upload "method =" post "enctype =" multipart / form-data "›');
res.write ('‹input type =" file ”name =” filetoupload ”› ');
res.write (' ‹input type =” submit ”› ');
res.write (' ‹/form› ');
return res.end ();
}
}). listen (8080);