admin管理员组

文章数量:1129469

Is there a way you can copy to clipboard in Node.js? Any modules or ideas what so ever? I'm using Node.js on a desktop application. Hopefully that clears up why I want it to be able to achieve this.

Is there a way you can copy to clipboard in Node.js? Any modules or ideas what so ever? I'm using Node.js on a desktop application. Hopefully that clears up why I want it to be able to achieve this.

Share Improve this question edited May 1, 2017 at 7:48 Sindre Sorhus 63.4k40 gold badges174 silver badges234 bronze badges asked Oct 15, 2011 at 14:50 TowerTower 103k131 gold badges364 silver badges517 bronze badges
Add a comment  | 

11 Answers 11

Reset to default 181

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.

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.

import clipboardy from 'clipboardy';

// Copy
clipboardy.writeSync('

本文标签: javascriptCopy to clipboard in NodejsStack Overflow