Access the system clipboard (copy/paste)
Cross-platform. Supports: macOS, Windows, Linux (including Wayland), OpenBSD, FreeBSD, Android with Termux, and modern browsers.
npm install clipboardyimport clipboard from 'clipboardy';
await clipboard.write('π¦');
await clipboard.read();
//=> 'π¦'
// Or use the synchronous API
clipboard.writeSync('π¦');
clipboard.readSync();
//=> 'π¦'Browser usage: Requires a secure context (HTTPS). Synchronous methods are not available in browsers.
Write (copy) to the clipboard asynchronously.
Returns a Promise<void>.
Type: string
The text to write to the clipboard.
await clipboard.write('π¦');Read (paste) from the clipboard asynchronously.
Returns a Promise<string>.
const content = await clipboard.read();
//=> 'π¦'Write (copy) to the clipboard synchronously.
Doesn't work in browsers.
Type: string
The text to write to the clipboard.
clipboard.writeSync('π¦');Read (paste) from the clipboard synchronously.
Returns a string.
Doesn't work in browsers.
const content = clipboard.readSync();
//=> 'π¦'The Linux binary is just a bundled version of xsel. The source for the Windows binary can be found here.
On Windows, clipboardy first tries the native PowerShell cmdlets (Set-Clipboard/Get-Clipboard) and falls back to the bundled binary if PowerShell is unavailable or restricted.
Yes. On Linux, clipboardy automatically detects Wayland sessions and uses wl-clipboard when available. If not, it gracefully falls back to X11 tools. Also works with WSLg (Windows Subsystem for Linux GUI). Install wl-clipboard using your distribution's package manager.
- clipboard-cli - CLI for this module
- clipboard-image - Get and set images on the clipboard
- copy-text-to-clipboard - Copy text to the clipboard in the browser