Node.JS fs.rename doesn't work

13,301

Solution 1

Debian Wheezy uses tmpfs for the /tmp folder by default.

This can be turned off by modifing /etc/default/rcS.

RAMTMP=yes

has to be set to

RAMTMP=no

Solution 2

This is another solution that works for me:

var fs = require("fs"),
util = require('util');
...
//fs.renameSync(files.upload.path, "/tmp/test.png");

var readStream = fs.createReadStream(files.upload.path)
var writeStream = fs.createWriteStream("/tmp/test.png");

util.pump(readStream, writeStream, function() {
    fs.unlinkSync(files.upload.path);
});
Share:
13,301
Thomaschaaf
Author by

Thomaschaaf

I am a developer.

Updated on June 21, 2022

Comments

  • Thomaschaaf
    Thomaschaaf almost 2 years

    Renaming a file on Debian Wheezy does not work using fs.rename or fs.renameSync.

    This only happens in files moved from /tmp/ to another location.

    The reported error is: EXDEV, cross-device link not permitted.