How to change upload path when use formidable with express in node.js
First of all you have to tell your app that you don't want the bodyParser
to handle file uploads.
app.use(express.bodyParser());
is equivalent to
app.use(express.json());app.use(express.urlencoded());app.use(express.multipart());
Remove the last line to deal with file uploads yourself. Add some custom options when initializing your form
var form = new formidable.IncomingForm({ uploadDir: __dirname + '/tmp', // don't forget the __dirname here keepExtensions: true});
Now your code should work.