Open misogihagi opened 4 years ago
If you are trying to use async / await
, you could use pify package to Promisify a callback-style function, here is an example
const pify = require('pify');
(async () => {
let sshkeys = await pify(keygen)({
location: location,
comment: comment,
password: password,
read: true,
format: format
});
console.log('sshkeys', sshkeys)
})();
You can use a promise-based API in my fork as well as the callback-based one
const keygen = require('@micalevisk/ssh-keygen')
async function runPromiseVersion() {
console.log('Generating key pair')
try {
const out = await keygen({
comment: 'john@doe.com',
read: true,
}); // just supply the second parameter here (as usual) if you don't want to return a Promise
console.log('Done generating key pairs');
console.log(out.key);
console.log(out.pubKey);
} catch (err) {
console.log('There was a problem:', err);
}
}
it doesn't have any dependencies.
keygen function is normal function not Promise or async function. I confused for a while and realized it may want some async methods.
code
result