Skip to content
Nodejs cp -R
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Include CLI documentation in, update usage.txt to reflect C… Dec 21, 2016
lib stablizing test Oct 31, 2017
.dockerignore adding Dockerfile for testing Oct 31, 2017
.gitignore Various changes (#48) Jun 26, 2017
.travis.yml Dropping Node 4.x testing Oct 31, 2017 changes Oct 31, 2017
Dockerfile adding Dockerfile for testing Oct 31, 2017
LICENSE Forgot license requirements Nov 2, 2012
cpr.d.ts typings for cpr Dec 29, 2016
package.json Update Ben Elliott's email address Jun 27, 2018

CPR (cp -R)

There are other modules out there that attempt this, but none did it the way I needed it to be done or they had issues and the author failed to fix them in a timely manner.


npm install cpr

Build Status

Build Status


var cpr = require('cpr');
var cpr = require('cpr').cpr; //Back compat

cpr('/path/from', '/path/to', {
    deleteFirst: true, //Delete "to" before
    overwrite: true, //If the file exists, overwrite it
    confirm: true //After the copy, stat all the copied files to make sure they are there
}, function(err, files) {
    //err - The error if any (err.list might be available with an array of errors for more detailed information)
    //files - List of files that we copied

cpr('/path/from', '/path/to', function(err, files) {
    //err - The error if any (err.list might be available with an array of errors for more detailed information)
    //      In the case of an error, cpr continues to copy files but returns this error object with all of the files that it failed to copy.
    //files - List of files that we copied


All options default to false.

  • deleteFirst: Delete the to directory with rimraf
  • overwrite: If the destination exists, overwrite it
  • confirm: After the copy operation, stat all the files and report errors if any are missing
  • filter: RegExp or function to test each file against before copying


If you give it a RegExp, it will use that to test the full absolute pathnames of the files and directories as they are being gathered. If any of them passes, it will not be copied. If you give it a function, it will use that with Array.filter on the list of full absolute pathnames of files and directories.


cpr can also be used from the command line which is useful for cross platform support.


cpr <source> <destination> [options]

Copies files from source to destination.


  • -d, --delete-first: Delete the destination directory before copying.
  • -f <regex>, --filter <regex>: Filter out any items that match <regex>, a case-insensitive regex pattern.
  • -h, --help: Display this usage info.
  • -o, --overwrite: Overwrite the destination exists if it exists.
  • -v, --version: Display the cpr version.

Note that the CLI's filter option is simpler than the original NodeJS API, only accepting case-insensitive regular expression patterns and not functions.


You can’t perform that action at this time.