Move File in ExpressJS/NodeJS

express, file, file-upload, node.js, ubuntu

Solution

Yes, fs.rename does not move file between two different disks/partitions. This is the correct behaviour. `fs.rename` provides identical functionality to `rename(2)` in linux.

Read the related issue posted here.

To get what you want, you would have to do something like this:

var source = fs.createReadStream('/path/to/source');
var dest = fs.createWriteStream('/path/to/dest');

source.pipe(dest);
source.on('end', function() { /* copied */ });
source.on('error', function(err) { /* error */ });

Problem

I'm trying to move uploaded file from `/tmp` to `home` directory using NodeJS/ExpressJS: ``` fs.rename('/tmp/xxxxx', '/home/user/xxxxx', function(err){ if (err) res.json(err); console.log('done renaming'); }); ``` But it didn't work and no error encountered. But when new path is also in `/tmp`, that will work. Im using Ubuntu, `home` is in different partition. Any fix? Thanks

Original source