Rename a file asynchronously using fs.rename
method of fs
module
of node.js
//Name of the file : renamefile-async.js
var fs = require('fs');
//you have to pass the Relative path of the file from the Current working directory.
fs.rename('assets/new.txt', 'assets/new_data.txt', (err) => {
if (err)
throw err;
console.log('File renamed successfully');
});
//To check it's Asynchronous nature !
console.log("This method is Asynchronous");
>node renamefile-async.js
This method is Asynchronous
File renamed successfully