var crypto = require("crypto"); module.exports = function(length) { var uid = ""; while (uid.length <= length) { uid += crypto .randomBytes(256) .toString("base64") .replace(/[^a-zA-Z0-9]/g, ""); } return uid.slice(0, length); };