Generating a random string / key with node

I'm interested on what's everyones opinion on generating random strings for things like keys, passwords, etc. within node.

I know crypto.randomBytes().toString("hex") is a possible candidate, but I've heard that it's cpu intensive and potentially thread blocking. It's convenient, but I'm not sure if the performance overhead is worth it.

Another possibility is simply implementing the following:

function randomString(num) {
 let chars = /* 0-9a-zA-Z */
 let string = "";
 for (let i = 0; i <= num; i++) {
   string += chars.charAt( Math.floor( Math.random() * chars.length-1 ) );
return string;

So I'm wondering which option is better.