{"id":13006,"library":"cp","title":"Node.js Simple File Copy Utility","description":"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.","status":"abandoned","version":"0.2.0","language":"javascript","source_language":"en","source_url":"git://github.com/stephenmathieson/node-cp","tags":["javascript","fs","copy","cp"],"install":[{"cmd":"npm install cp","lang":"bash","label":"npm"},{"cmd":"yarn add cp","lang":"bash","label":"yarn"},{"cmd":"pnpm add cp","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only. Attempting to use ESM `import` will result in a runtime error.","wrong":"import cp from 'cp';","symbol":"cp","correct":"const cp = require('cp');"},{"note":"The synchronous copy function is a named property of the default CommonJS export.","wrong":"import { sync } from 'cp';","symbol":"cp.sync","correct":"const cp = require('cp');\ncp.sync(source, destination);"},{"note":"The primary asynchronous function is the default export, not a named export. It exclusively uses Node.js-style callbacks for async operations.","wrong":"const { cp } = require('cp');","symbol":"Async Callback","correct":"const cp = require('cp');\ncp(source, destination, (err) => { /* handle error */ });"}],"quickstart":{"code":"const cp = require('cp');\nconst fs = require('fs');\nconst path = require('path');\n\nconst sourceFile = path.join(__dirname, 'source.txt');\nconst destFileSync = path.join(__dirname, 'destination-sync.txt');\nconst destFileAsync = path.join(__dirname, 'destination-async.txt');\n\n// Create a dummy source file for the example\nfs.writeFileSync(sourceFile, 'Hello from source.txt!');\n\nconsole.log('Starting file copy examples...');\n\n// 1. Synchronous Copy\ntry {\n  cp.sync(sourceFile, destFileSync);\n  console.log(`Synchronous copy complete: ${sourceFile} -> ${destFileSync}`);\n} catch (error) {\n  console.error('Synchronous copy failed:', error.message);\n}\n\n// 2. Asynchronous Copy with Callback\ncp(sourceFile, destFileAsync, (err) => {\n  if (err) {\n    console.error('Asynchronous copy failed:', err.message);\n    return;\n  }\n  console.log(`Asynchronous copy complete: ${sourceFile} -> ${destFileAsync}`);\n\n  // Clean up created files\n  fs.unlinkSync(sourceFile);\n  fs.unlinkSync(destFileSync);\n  fs.unlinkSync(destFileAsync);\n  console.log('Cleaned up temporary files.');\n});\n","lang":"javascript","description":"Demonstrates both synchronous and asynchronous file copying using `cp` and `cp.sync` with cleanup."},"warnings":[{"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`.","message":"The `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.","severity":"breaking","affected_versions":">=0.2.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you are using `const cp = require('cp');` for CommonJS environments, as the package does not support ESM `import` statements.","cause":"Attempting to use `cp` as a named import or incorrectly destructuring the CommonJS module in an ESM context.","error":"TypeError: cp is not a function"},{"fix":"Verify that the `src` path points to an existing file before calling `cp` or `cp.sync`. Implement path validation or `fs.existsSync` checks.","cause":"The source file specified in the `cp` call does not exist at the provided path.","error":"Error: ENOENT: no such file or directory, open '/path/to/source.txt'"},{"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`).","cause":"Insufficient read/write permissions for either the source file or the destination directory/file.","error":"Error: EPERM: operation not permitted, copyfile '/path/to/source.txt' -> '/path/to/destination.txt'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}