recursive-copy is a robust and flexible utility for copying files and directories within a Node.js environment. It is currently stable at version 2.0.14 and appears to be actively maintained, with a focus on reliability and advanced use cases for filesystem operations. Key features include recursive directory copying, sophisticated filtering using functions, regular expressions, or globs, dynamic file renaming, and stream-based content transformation. It differentiates itself by integrating with `graceful-fs` and `mkdirp` to handle common filesystem errors, automatically filters out OS junk files by default, and provides an event-driven interface alongside traditional callback and promise-based APIs. This makes it suitable for complex build processes or file manipulation tasks where fine-grained control and error handling are crucial, offering a more feature-rich alternative to basic `fs.copyFile` or `fs.cp` methods.
npm install recursive-copyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to recursively copy a directory, including dotfiles, with specific filters, using the promise-based `async/await` syntax. It also includes cleanup.
Set the `overwrite: true` option in the `options` object when calling `copy()` if existing files should be replaced.
To include dotfiles in the copy operation, set the `dot: true` option in the `options` object.
Set `expand: true` in the `options` object to make `recursive-copy` resolve and copy the actual content pointed to by symbolic links, rather than the links themselves.
Thoroughly test your `filter` options on a small dataset. For glob patterns, ensure they correctly reflect paths relative to your `src` directory. Consider using a `filter` function for complex logic to gain explicit control and debuggability.
Ensure the Node.js process has appropriate read permissions for the source path and write permissions for the destination path. This may involve running the application with elevated privileges or adjusting directory permissions on the operating system.
Ensure the process has write access to the `dest` directory and its parent folders. This might require changing directory permissions (`chmod`) or running the application with administrative privileges.
Verify that the `src` argument points to an actual, existing file or directory on the file system and that the Node.js process has read access to it.
Review your `transform` function. Ensure it always emits `Buffer` or `string` data for file content, and correctly handles `done(null, chunk)` or `done(null, null)` for the end of a stream.