How to generate short unique alphanumeric with Node.js and JavaScript?

Sometimes, we want to generate short unique alphanumeric with Node.js and JavaScript.

In this article, we’ll look at how to generate short unique alphanumeric with Node.js and JavaScript.

How to generate short unique alphanumeric with Node.js and JavaScript?

To generate short unique alphanumeric with Node.js and JavaScript, we can use the number’s toString method with base 36.

For instance, we write:

const s = (100000000000).toString(36);
console.log(s)

to call toString on 100000000000 with 36 to return a string with letters and digits.

As a result, s is '19xtf1ts'.

Conclusion

To generate short unique alphanumeric with Node.js and JavaScript, we can use the number’s toString method with base 36.