The crypto.randomUUID() is an inbuilt application programming interface of class Crypto within crypto module which is used to generate a random RFC 4122 Version 4 UUID.
Syntax:
const crypto.randomUUID([options])
Parameters: This function takes the disableEntropyCache as a parameter
Return Value: This function returns a random RFC 4122 Version 4 UUID.
Example 1:
index.js
<script>
const crypto = require( 'crypto' )
const val = crypto.randomUUID({disableEntropyCache : true });
console.log( "RFC 4122 Version 4 UUID : " + val)
</script>
|
Run the index.js file using the following command.
node index.js
Output:
RFC 4122 Version 4 UUID : 88368f2a-d5db-47d8-a05f-534fab0a0045
Example 2:
index.js
<script>
const crypto = require( 'crypto' )
console.log(crypto.randomUUID())
</script>
|
Run the index.js file using the following command.
node index.js
Output:
e2d3286f-2d8f-471a-bacb-1e5d28d8727e
Reference: https://nodejs.org/dist/latest-v15.x/docs/api/crypto.html#crypto_crypto_randomuuid_options
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
22 Apr, 2021
Like Article
Save Article