skip to content
Just Change Direction

How to copy to clipboard using node

/ 1 min read

I have a DB seed script I am using and it outputs a list of uuids of the data it creates so I can use them to delete the previously created data in the next run. So far I have been manually copying the uuids from the terminal and pasting them into the delete script. This handy trick allows me to skip the copying step and just paste them straight in.

function copyToClipboard(data: string) {
var proc = require("child_process").spawn("pbcopy");
proc.stdin.write(data);
proc.stdin.end();
}