lundi 20 avril 2015

How to trigger error on fs.rename command if file already exists?

I have the following code that moves files from one directory to another:

var fs = require('fs'),
    oldPath = 'firstfile.txt',
    newPath = 'temp/firstfile.txt';

fs.rename(oldPath, newPath, function (err) {
    console.log('rename callback ', err); 
});

Is it possible to trigger error if newPath file already exists?

Aucun commentaire:

Enregistrer un commentaire