
Generate UUID-like strings with Crypto in Node.JS
const crypto = require('crypto');
let uuidStyleStr = crypto.randomBytes(4).toString('hex') + "-" +
crypto.randomBytes(2).toString('hex') + "-" +
crypto.randomBytes(2).toString('hex') + "-" +
crypto.randomBytes(2).toString('hex') + "-" +
crypto.randomBytes(6).toString('hex');
console.log(uuidStyleStr);
Sample output:
b99c8dbc-1258-a348-3046-1674613bd86a