Как реализовать копирование и перемещение директорий и папок на Node.js?

Подскажите какой-нибудь адекватный способ копирования и перемещения директорий и папок на Node.js.

К сожаления, сам ничего найти не смог. Спасибо


Ответы (1 шт):

Автор решения: Aziz Umarov

Можете использовать ncp

var ncp = require('ncp').ncp;
 
ncp.limit = 16;
 
ncp(source, destination, function (err) {
 if (err) {
   return console.error(err);
 }
 console.log('done!');
});

Или же используйте fs

const fs = require('fs');
const { COPYFILE_EXCL } = fs.constants;

// destination.txt will be created or overwritten by default.
fs.copyFileSync('source.txt', 'destination.txt');
console.log('source.txt was copied to destination.txt');

// By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
fs.copyFileSync('source.txt', 'destination.txt', COPYFILE_EXCL);
→ Ссылка