A UUID is a Universal Unique Identifier is a method for generating ids that have been standardized by the Open Software Foundation (OSF).

You can generate UUIDs in Node.js through the node-UUID. It is a speedy and straightforward way of generating Version 1 & 4 UUIDs.

Here's how to generate UUIDs
  • Install the node-uuid through the npm manager using npm install uuid.
  • Use it in your script like this:

const uuidv1 = require('uuid/v1')
const uuidv4 = require('uuid/v4')
var uuid1 = uuidv1()
var uuid5 = uuidv4()

Here is how your output would look. Although, due to the nature of UUIDs, your generated IDs may be completely different.

Output

uuid1 v1 => 6bf958f0-95ed-17e8-sds37-23f5ae311cf6
uuid5 v4 => 356fasda-dad8d-42b7-98b8-a89ab58a645e

 

BY Best Interview Question ON 25 Jun 2020