NODEJS upload file to folder nodejs - Net-Raft.com

Welcome aboard! We are happy you are here and wish you good net-raft!




Just a Web Code Solution
join us

upload file to folder nodejs


 1397

NODEJS


2

// 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);


By        
The power of the user (%)
80%



The most helpful NODEJS solutions

get user ipget user ipNODEJS

Click to see more ...

  8.4K     1.7K

how to get client netmask using node.js ?how to get client netmask using node.js ?NODEJS

Click to see more ...

  4.8K     557

How to get client machine name and computer name with node.js?How to get client machine name and computer name with node.js?NODEJS

Click to see more ...

  12.5K     440

how to get client local ip address using node.js ?how to get client local ip address using node.js ?NODEJS

Click to see more ...

  2.5K     311

How to get client ip address using node.jsHow to get client ip address using node.jsNODEJS

Click to see more ...

  2.3K     271

How to combine node.js and jquery ?How to combine node.js and jquery ?NODEJS

Click to see more ...

  1.7K     247

how to detect tablet, iPad, iPhone, Android and Blackberry using nodejs ?how to detect tablet, iPad, iPhone, Android and Blackberry using nodejs ?NODEJS

Click to see more ...

  2K     161

get client region using node.js ?get client region using node.js ?NODEJS

Click to see more ...

  1.7K     128

get real user ip address using node.js?get real user ip address using node.js?NODEJS

Click to see more ...

  1.4K     124

get server ip address from hostname nodejsget server ip address from hostname nodejsNODEJS

Click to see more ...

  3.2K     122

Welcome aboard!
We are happy you are here and
wish you good net-raft!