xxxxxxxxxx
import { v4 as uuidv4 } from 'uuid';
uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
xxxxxxxxxx
// normal project
npm i uuid
import { v4 as uuidv4 } from 'uuid';
uuidv4();
// typescript
npm i uuid
npm i -D @types/uuid
import { v4 as uuidv4 } from 'uuid';
uuidv4();
xxxxxxxxxx
const { v4: uuidv4 } = require('uuid');
uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
xxxxxxxxxx
const { uuid } = require('uuidv4');
console.log(uuid());
// => '11bf5b37-e0b8-42e0-8dcf-dc8c4aefc000'
xxxxxxxxxx
import { v4 as uuidv4 } from 'uuid';
uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'