How to generate unique ID with node.js

Install NPM uuid package (sources: https://github.com/uuidjs/uuid):

npm install uuid

and use it in your code, e.g. with ES6 imports:

import { v4 as uuidv4, v6 as uuidv6 } from 'uuid';

uuidv4();
uuidv6();

Or with CommonJS requires:

const { 
  v1: uuidv1,
  v4: uuidv4,
} = require('uuid');

uuidv1(); // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a' 
uuidv4(); // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1' 

For

Leave a Comment