Skip to content

Instantly share code, notes, and snippets.

@bhubr
Created July 23, 2019 19:21
Show Gist options
  • Save bhubr/b0432133c612b175d97c1d02a0731fe9 to your computer and use it in GitHub Desktop.
Save bhubr/b0432133c612b175d97c1d02a0731fe9 to your computer and use it in GitHub Desktop.
Generate 64-character long hexadecimal token with Node.js
const crypto = require('crypto');
const util = require('util');
const randomBytesAsync = util.promisify(crypto.randomBytes);
const generateToken = async () => {
const buf = await randomBytesAsync(32);
return buf.toString('hex');
};
module.exports = generateToken;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment