Skip to content

Instantly share code, notes, and snippets.

@daffl
Created May 13, 2020 18:19
Show Gist options
  • Save daffl/05634864f94917f834ecf99ff006fa65 to your computer and use it in GitHub Desktop.
Save daffl/05634864f94917f834ecf99ff006fa65 to your computer and use it in GitHub Desktop.
Using the 1Password CLI in NodeJS
const runOp = args => {
const cmd = 'op';
const proc = spawn(cmd, args, {
stdio: [
'inherit',
'pipe',
'inherit'
]
});
return new Promise((resolve, reject) => {
let stdout = '';
proc.stdout.on('data', data => (stdout += data.toString()));
proc.on('close', code => code ? reject(new Error(`1Password CLI exited with error status ${code}`)) : resolve(stdout));
}).then(stdout => JSON.parse(stdout));
}
runOp([ 'get', 'item', 'my-secret-key' ]).then(item => {
const { password } = item.details;
// Use secret password here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment