Copy to clipboard in Node.js?
Check out clipboardy
. It lets you copy/paste cross-platform. It is more actively maintained than the copy-paste
module mentioned in another answer and it fixes many of that module's issues.
const clipboardy = require('clipboardy');
// Copy
clipboardy.writeSync('ð¦');
// Paste
clipboardy.readSync();
//ð¦
For OS X:
function pbcopy(data) {
var proc = require('child_process').spawn('pbcopy');
proc.stdin.write(data); proc.stdin.end();
}
write()
can take a buffer or a string. The default encoding for a string will be utf-8.