fs.createWriteStream error:ENOENT

dir, express, multipart, node.js, upload

Solution

The directory you are trying to read does not exist! Make sure that the path exists.

Problem

I use connect-busboy to handle file uploading, here is the code ``` req.busboy.on('file', function(fieldname, file, filename, encoding, mimetype) { var type = mimetype.split('/')[1] var newName = (new Date()).valueOf(); var saveTo = path.join(__dirname, '../../userUpload',req.user._id+'', newName+'.'+type); file.pipe(fs.createWriteStream(saveTo,{flags: 'w'})); }); ``` as you can see, I tried to save the uploaded file in a dynamic dir(named with user._id), and a new file name; but it gives me an error says ``` "Error: ENOENT, open '\userUpload\53a65fde4e22939811aa306d\1404636837084.mp4' " ``` but when I manully create the user._id dir first, it will work, so fs.createWriteStream can not handle the dynamic dir right? how can i do this?

Original source