Welcome aboard! We are happy you are here and wish you good net-raft!
// index.js
var express = require('express'); // express Web Server
var formidable = require('formidable'); // npm install formidable
var app = express();
app.get('/', function (req, res){
res.sendFile(__dirname + '/index.html'); // index.html
});
app.post('/', function (req, res){
var form = new formidable.IncomingForm();
form.parse(req);
form.on('fileBegin', function (name, file){
file.path = __dirname + '/myfolder/' + file.name; // path where file will be uploaded
});
form.on('file', function (name, file){
console.log('Uploaded ' + file.name);
});
res.sendFile(__dirname + '/index.html');
});
var server = app.listen(3000, function() {
console.log('Listening on port %d', server.address().port);
});
// index.html
<!DOCTYPE html>
<html>
<head>
<title>Nodejs Express Upload File</title>
</head>
<body>
<form action="/" enctype="multipart/form-data" method="post">
<input type="file" name="upload" multiple>
<input type="submit" value="Upload">
</form>
</body>
</html>
The most helpful NODEJS solutions