Answer the question
In order to leave comments, you need to log in
How does async/await work in Node?
Code example:
const fs = require('fs');
const keypair = require('keypair');
console.log('Before');
async function generate(bits=2048) {
let pair = await new Promise((res, rej) => {
res(keypair({
bits
}));
});
console.log('Generated');
fs.writeFileSync('./private.key', pair['private']);
fs.writeFileSync('./public.key', pair['public']);
}
generate(2048);
console.log('After');
$ node keypair.js
Before
# Ожидание 2-8 сек
After
Generated
$ node keypair.js
Before
After
# Ожидание 2-8 сек
Generated
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question