Welcome aboard! We are happy you are here and wish you good net-raft!
// you must install "npm install formidable" in node.js command prompt
var http = require('http');
var formidable = require('formidable');
var fs = require('fs');
http.createServer(function (req, res) {
var dir = './myfolder'; // your folder on the desktop
if (fs.existsSync(dir)){ // check if your folder exists
if (req.url == '/fileupload') { // your filename
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files) {
var oldpath = files.filetoupload.path;
var newpath = 'C:/Users/yourpath.../myfolder/' + files.filetoupload.name; // upload to
fs.rename(oldpath, newpath, function (err) {
if (err) throw err;
res.write('File uploaded and moved!');
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);
The most helpful NODEJS solutions