copy-paste is a Node.js utility designed to provide read/write access to the system clipboard across different operating systems. It achieves cross-platform compatibility by wrapping native command-line tools: `pbcopy` and `pbpaste` for macOS, `xclip` for Linux and BSD systems, and `clip` for Windows. This abstraction allows developers to interact with the clipboard using a unified JavaScript API. The package offers both a traditional callback-based interface for asynchronous operations and a modern Promise-based API for `async/await` patterns, accessible via a submodule. It is currently at version 2.2.0 and, while not actively undergoing rapid feature development, it remains a maintained package for fundamental clipboard interactions in Node.js environments. Its primary differentiator is its robust cross-platform wrapper for underlying system utilities, abstracting away the OS-specific commands.
npm install copy-pasteVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the asynchronous copy and paste operations using the promise-based API, including copying plain text and stringified JSON, then pasting and parsing the content. It also includes basic error handling for missing system dependencies.
Ensure the required system clipboard utility is installed and available in your system's PATH. For Linux, `xclip` is commonly needed (e.g., `sudo apt-get install xclip` or `sudo yum install xclip`).
Use `const clipboard = require('copy-paste');` (or `require('copy-paste/promises')`) to import the package. If your project is pure ESM, you might need to use dynamic `import()` for CommonJS modules or transpile your code.Prefer importing `copy` and `paste` functions directly using `const { copy, paste } = require('copy-paste');` to maintain module scope and avoid global side effects.When retrieving content copied with `copy.json`, manually parse the result using `JSON.parse(text)` after pasting if you need to reconstitute the original object.
Install the `xclip` utility on your Linux system. For Debian/Ubuntu-based systems: `sudo apt-get install xclip`. For RHEL/Fedora-based systems: `sudo yum install xclip`.
Use CommonJS `require()` syntax instead: `const { copy, paste } = require('copy-paste');` or `const clipboard = require('copy-paste/promises');`.Ensure you correctly import the functions before use, e.g., `const { copy, paste } = require('copy-paste');` or `const clipboard = require('copy-paste/promises');`.No dependency data recorded yet.