title: How to use async/await using crypto.randomBytes in nodejs?
body: <pre><code>const crypto = require('crypto');
  
  async function getKey(byteSize) {
      let key = await crypto.randomBytes(byteSize);
      return key;
  }
  
  async function g() {
      let key = await getKey(12);
      return key;
  }
  
  console.log(g());
  
  console.log('hello - want this called after g() above');
  </code></pre>
  <p>I've been at this for an hour and I can't understand how to ensure that I get a key using async/await. I get a Promise-pending no matter what I do.</p>
  <p>I've also tried this:</p>
  <pre><code>async function getKey(byteSize) {
      let key = await crypto.randomBytes(byteSize);
      return key;
  }
  
  getKey(12).then((result) =&gt; { console.log(result) })
  
  
  console.log('hello');
  </code></pre>
  <p>... to no avail! Which was inspired by:
  <a href="https://stackoverflow.com/questions/61528374/how-to-use-await-with-promisify-for-crypto-randombytes">How to use await with promisify for crypto.randomBytes?</a></p>
  <p>Can anyone help me with this?</p>
  <p>All I'm trying to do is to get randomBytes async. using the async./await block but ensure that it fulfills the promise before I carry on in the code.</p>