ncp is an asynchronous recursive file and directory copying utility for Node.js, designed to mimic the `cp -r` command but with a pure JavaScript, non-blocking implementation. The current stable version, 2.0.0, as indicated in the prompt, has not seen active development for many years (last commit 6 years ago on GitHub), suggesting it is an abandoned project with no current release cadence. Its key differentiators include a programmatic API that allows for fine-grained control over the copying process, such as setting a global concurrency limit, filtering files via regular expressions or custom functions, applying streaming transformations during the copy, and flexible error handling (either stopping on the first error or continuing while logging all errors). It offers an entirely asynchronous approach to file system operations, which was a significant advantage in early Node.js environments for non-blocking I/O compared to synchronous `cp -r` alternatives.
npm install ncpVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `ncp` programmatically to recursively copy a directory. It showcases setting a global concurrency limit, applying a file filter (only copying `.txt` files and directories), using a transform stream to modify file content (uppercase), and configuring `ncp` to stop immediately on the first error encountered.
Consider using actively maintained alternatives such as `fs-extra` (for general file system operations, including `copy` and `copySync`) or the native Node.js `fs.cp` (available in Node.js >=16.0.0) for modern projects.
Always use CommonJS `require` syntax: `const { ncp } = require('ncp');`. For projects requiring ESM, consider migrating to a modern alternative.Ensure you correctly access the `ncp` property: `const { ncp } = require('ncp');` or `const ncp = require('ncp').ncp;`.While `ncp` itself doesn't offer a per-call concurrency option, alternatives like `fs-extra` allow concurrency settings directly within their `copy` function options, avoiding global state.
To make `ncp` stop on the first error, similar to `cp -r`, you must explicitly set the `options.stopOnErr` property to `true`: `ncp(source, destination, { stopOnErr: true }, callback);`.Correct the import statement to `const { ncp } = require('ncp');` or `const ncp = require('ncp').ncp;`.Reduce the `ncp.limit` value to a lower number (e.g., 4 or 8) to decrease concurrent file operations. Ensure any custom `options.transform` streams correctly pipe data and handle stream completion/errors.
Verify that the user running the Node.js process has appropriate file system permissions for both the source and destination paths. You may need to change directory/file permissions or run the process with elevated privileges.
No dependency data recorded yet.