Registry / data / cp
library2020.12.3jsnpmunverified

The `cp` package is a lightweight Node.js utility designed for straightforward file copying, offering both asynchronous callback-based and synchronous APIs. Its current stable version is 0.2.0, with the last notable activity and publication on npm dating back to November 2014. Due to its age and lack of maintenance over many years, this package is considered abandoned. It was initially differentiated by its simplicity and direct approach to file operations, contrasting with more feature-rich but potentially complex alternatives or the direct use of Node.js's native `fs` module. The asynchronous API primarily uses callbacks, although the README mentions `yield cp(src, dest)`, indicating a pattern likely intended for use with generator-based flow control libraries (like `co`) that were common before native `async/await` became widespread. The package does not natively support modern promise-based or `async/await` patterns, which are now standard in Node.js.

npm install cp
INSTALL
IMPORT
SIG · CP
C
cp
datajavascriptv2020.12.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cp
const cp = require('cp');
import cp from 'cp';
This package is CommonJS-only. Attempting to use ESM `import` will result in a runtime error.
cp.sync
const cp = require('cp'); cp.sync(source, destination);
import { sync } from 'cp';
The synchronous copy function is a named property of the default CommonJS export.
Async Callback
const cp = require('cp'); cp(source, destination, (err) => { /* handle error */ });
const { cp } = require('cp');
The primary asynchronous function is the default export, not a named export. It exclusively uses Node.js-style callbacks for async operations.

Demonstrates both synchronous and asynchronous file copying using `cp` and `cp.sync` with cleanup.

const cp = require('cp'); const fs = require('fs'); const path = require('path'); const sourceFile = path.join(__dirname, 'source.txt'); const destFileSync = path.join(__dirname, 'destination-sync.txt'); const destFileAsync = path.join(__dirname, 'destination-async.txt'); // Create a dummy source file for the example fs.writeFileSync(sourceFile, 'Hello from source.txt!'); console.log('Starting file copy examples...'); // 1. Synchronous Copy try { cp.sync(sourceFile, destFileSync); console.log(`Synchronous copy complete: ${sourceFile} -> ${destFileSync}`); } catch (error) { console.error('Synchronous copy failed:', error.message); } // 2. Asynchronous Copy with Callback cp(sourceFile, destFileAsync, (err) => { if (err) { console.error('Asynchronous copy failed:', err.message); return; } console.log(`Asynchronous copy complete: ${sourceFile} -> ${destFileAsync}`); // Clean up created files fs.unlinkSync(sourceFile); fs.unlinkSync(destFileSync); fs.unlinkSync(destFileAsync); console.log('Cleaned up temporary files.'); });
Debug
Known issues
breakingThe `cp` package is considered abandoned. Its last update was over 11 years ago (November 2014), meaning it lacks modern features, bug fixes, and critical security updates. Relying on abandoned packages can introduce significant supply chain vulnerabilities and lead to compatibility issues with newer Node.js versions.
fix
Migrate to a actively maintained and more robust file system utility like `fs.promises.copyFile` (native to Node.js since v8.5.0), `fs-extra` (for broader utility), or `cp-file`.
affects: >=0.2.0
gotchaThe package exclusively uses Node.js-style callbacks for asynchronous operations and does not natively support Promises or `async/await`. The mention of `yield cp(src, dest)` in the README refers to generator-based flow control (e.g., with `co`), which is an outdated pattern in modern Node.js development.
fix
If migrating is not immediately possible, use Node.js's `util.promisify` to convert the callback-based API to a Promise-based one for use with `async/await`, but prioritize migration to a modern library.
affects: >=0.1.0
gotchaThe `cp` package may not handle complex file system scenarios robustly, such as directory copying, symlinks, or maintaining file permissions and attributes across different operating systems as comprehensively as modern alternatives. Its API is limited to simple file-to-file copies.
fix
For advanced copying needs (recursive, preserving permissions, error handling), use `fs-extra`'s `copy` function, or Node.js's native `fs.cp` (since v16.7.0) / `fs.cpSync` (since v16.7.0) which supports recursive copying and more options.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: cp is not a function
Attempting to use `cp` as a named import or incorrectly destructuring the CommonJS module in an ESM context.
fix
Ensure you are using `const cp = require('cp');` for CommonJS environments, as the package does not support ESM `import` statements.
Error: ENOENT: no such file or directory, open '/path/to/source.txt'
The source file specified in the `cp` call does not exist at the provided path.
fix
Verify that the `src` path points to an existing file before calling `cp` or `cp.sync`. Implement path validation or `fs.existsSync` checks.
Error: EPERM: operation not permitted, copyfile '/path/to/source.txt' -> '/path/to/destination.txt'
Insufficient read/write permissions for either the source file or the destination directory/file.
fix
Ensure the Node.js process has the necessary file system permissions to read the source and write to the destination. On Linux/macOS, consider `sudo` for scripts or checking directory ownership and permissions (e.g., `chmod`).
Upgrade
Version history
2020.12.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
cp — npm install cp · libregistry