Skip to content

Instantly share code, notes, and snippets.

@matinkaboli
Created February 11, 2018 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matinkaboli/1d7213f6968e18f0a5b805a665e4d079 to your computer and use it in GitHub Desktop.
Save matinkaboli/1d7213f6968e18f0a5b805a665e4d079 to your computer and use it in GitHub Desktop.
Random String in Node.js (only with built-it packages)
import crypto from 'crypto';
function randomString() {
return new Promise((resolve, reject) => {
crypto.pseudoRandomBytes(16, (err, raw) => {
if (err) {
reject(err);
} else {
const r = raw.toString('hex') + Date.now();
resolve(r);
}
});
});
}
export default randomString;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment