Node fs copy a folder

y. lu picture y. lu · Aug 23, 2016 · Viewed 16k times · Source

I am trying to copy a folder using Node fs module. I am familiar with readFileSync() and writeFileSync() methods but I am wondering what method I should use to copy a specified folder?

Answer

user3248186 picture user3248186 · Oct 13, 2016

You can use fs-extra to copy contents of one folder to another like this

var fs = require("fs-extra");

fs.copy('/path/to/source', '/path/to/destination', function (err) {
  if (err) return console.error(err)
  console.log('success!')
});

There's also a synchronous version.