English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
To install Node fs using NPM (Node Package Manager)-extra package, please run the following command in the terminal.
node-js-copy-a-foder.js
// Introduce fs-extra package var fs = require("fs-extra"); var source = 'folderA' var destination = 'folderB' // Copy the source folder to the destination fs.copy(source, destination, function(err) { if (err){ console.log('An error occurred while copying the folder.') return console.error(err) } console.log('Copy completed!') });
Run the above script in a terminal command with Node
Node.js Script Terminal Output
arjun@arjun-VPCEH26EN:~/workspace/nodejs$ node node-js-copy-a-foder.js Copy completed!
In this Node.js tutorial-Node.js File System (FS) - Copy a Folder in Node.js, we have learned to installNode.js File System (FS)-AdditionalPackages andFolder or Directory Copy(including files and some folders), used in other locations Node.js File System (FS)-EXTRAPackage with example scripts.