# JavaScript UUID and ID generation libraries

JavaScript UUID libraries generate unique identifiers for records, requests, and files without a central counter. A generator builds each ID from random bytes, a timestamp, or both, in a fixed format such as a standard UUID or a shorter URL-safe string. These libraries let apps and distributed services create IDs that stay unique across machines.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [uuid](#uuid) | 1.5B | 15.3K | Oct 2026 | MIT |
| [nanoid](#nano-id) | 1.5B | 27.1K | Oct 2026 | MIT |
| [crypto-random-string](#crypto-random-string) | 153.7M | 594 | Jul 2026 | MIT |
| [@paralleldrive/cuid2](#cuid) | 115.6M | 3.4K | Jan 2026 | MIT |
| [uid](#uid) | 86.9M | 665 | Mar 2023 | MIT |
| [ulid](#ulid) | 66.6M | 3.4K | Nov 2025 | MIT |
| [@lukeed/uuid](#lukeed-uuid) | 33.2M | 410 | Mar 2023 | MIT |
| [guid-typescript](#guid-typescript) | 28.6M | 54 | Oct 2018 | ISC |

Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[uuid](#uuid) has the most monthly downloads in this comparison, at 1.5B.

## Capabilities

| Library | RFC UUID generation | Time sortable mode | Custom alphabet |
| --- | --- | --- | --- |
| [uuid](#uuid) | Yes | Yes | No |
| [nanoid](#nano-id) | No | No | Yes |
| [crypto-random-string](#crypto-random-string) | No | No | Yes |
| [@paralleldrive/cuid2](#cuid) | No | No | No |
| [uid](#uid) | No | No | No |
| [ulid](#ulid) | No | Yes | No |
| [@lukeed/uuid](#lukeed-uuid) | Yes | No | No |
| [guid-typescript](#guid-typescript) | No | No | No |

## Libraries

### uuid

[GitHub](https://github.com/uuidjs/uuid) · [npm](https://www.npmjs.com/package/uuid) · [Docs](https://github.com/uuidjs/uuid#readme)

Generates standard UUID variants and provides parsing, validation and version checks.

- Downloads / mo: 1.5B
- Stars: 15.3K
- Last release: 14.0.3
- License: MIT
- Capabilities: [From the uuid docs](https://github.com/uuidjs/uuid#readme)

**Strengths**

- **Generates reordered timestamp UUIDs.** Choose a reordered timestamp variant when ID ordering matters.
- **Checks UUID version constraints.** Combine validate and version when a field requires a specific UUID version.

**Watch out for**

- **Current releases require ES modules.** CommonJS imports are unsupported in current uuid releases.
- **Options bypass timestamp generator state.** Passing options disables the internal timestamp-UUID state.

```sh
npm install uuid
```

**Kong/insomnia** (40.2K stars)

[Kong/insomnia](https://github.com/Kong/insomnia) 

```typescript
export function generateId(prefix?: string) {
  const id = uuidv4().replace(/-/g, '');

  if (prefix) {
    return `${prefix}_${id}`;
  }
  return id;
}
```

[packages/insomnia/src/common/misc.ts](https://github.com/Kong/insomnia/blob/1d21a994de311f5c4e6579def0c93eb23b8fa8ce/packages/insomnia/src/common/misc.ts#L91-L98) · [More projects using uuid →](https://dashboard.exa.ai/playground/search?q=Projects%20using%20uuid%20for%20identifier%20generation%20and%20validation&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```typescript
import { v4 as uuidv4 } from 'uuid';

console.log(uuidv4());
```

From [README.md](https://cdn.jsdelivr.net/npm/uuid@14.0.3/README.md)

### nanoid

[GitHub](https://github.com/ai/nanoid) · [npm](https://www.npmjs.com/package/nanoid) · [Docs](https://github.com/ai/nanoid#readme)

Generates random string identifiers with configurable lengths and alphabets.

- Downloads / mo: 1.5B
- Stars: 27.1K
- Last release: 6.0.2
- License: MIT
- Capabilities: [From the nanoid docs](https://github.com/ai/nanoid#readme)

**Strengths**

- **Customizes alphabet and length.** Use customAlphabet to define the characters and size of generated IDs.
- **Accepts a custom random source.** Use customRandom to replace the default random-byte generator.

**Watch out for**

- **Seeded results vary across versions.** Do not expect seeded output to stay identical after library upgrades.
- **Generated React keys are unstable.** Use stored item IDs for React keys across renders.

```sh
npm install nanoid
```

**Quickstart**

```typescript
import { nanoid } from 'nanoid';

console.log(nanoid());
```

From [README.md](https://cdn.jsdelivr.net/npm/nanoid@6.0.2/README.md) · [Find projects using nanoid →](https://dashboard.exa.ai/playground/search?q=Projects%20using%20nanoid%20for%20identifier%20generation%20and%20validation&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### crypto-random-string

[GitHub](https://github.com/sindresorhus/crypto-random-string) · [npm](https://www.npmjs.com/package/crypto-random-string) · [Docs](https://github.com/sindresorhus/crypto-random-string#readme)

Generates a cryptographically strong random string.

- Downloads / mo: 153.7M
- Stars: 594
- Last release: 6.0.0
- License: MIT
- Capabilities: [From the crypto-random-string docs](https://github.com/sindresorhus/crypto-random-string#readme)

```sh
npm install crypto-random-string
```

**netless-io/flat-server** (684 stars)

[netless-io/flat-server](https://github.com/netless-io/flat-server) 

```javascript
async createRoom(params: CreateRoomParams): Promise<{ roomUUID: string; inviteCode: string }> {
        await this.assertExists();

        const { userUUID, ownerUUID, title, type, beginTime, endTime } = params;

        const result = await userDAO.find(this.DBTransaction, ["user_uuid"], {
            user_uuid: In([userUUID, ownerUUID]),
        });
        if (result.length < 2) {
            const users = result.map(e => e.user_uuid);

            this.logger.error("user not found", {
                developerPartner: {
                    userUUID,
                    ownerUUID,
                    userMissing: !users.includes(userUUID),
                    ownerMissing: !users.includes(ownerUUID),
                },
            });

            throw new FError(ErrorCode.UserNotFound);
        }

        const roomUUID = generateRoomUUID();
        const roomService = new ServiceRoom(roomUUID, ownerUUID);

        await Promise.all([
            roomService.create({ title, type, beginTime, endTime }, this.DBTransaction),
            roomUserDAO.insert(this.DBTransaction, [
                {
                    room_uuid: roomUUID,
                    user_uuid: userUUID,
                    rtc_uid: cryptoRandomString({ length: 6, type: "numeric" }),
                },
                {
                    room_uuid: roomUUID,
                    user_uuid: ownerUUID,
                    rtc_uid: cryptoRandomString({ length: 6, type: "numeric" }),
                },
            ]),
            partnerRoomDAO.insert(this.DBTransaction, {
                partner_uuid: this.partnerUUID,
                room_uuid: roomUUID,
            }),
        ]);

        rtcQueue(roomUUID, 0);

        const inviteCode = await generateRoomInviteCode("ordinary", roomUUID, this.logger);

        return { roomUUID, inviteCode };
    }
```

[src/v2/services/developer/partner.ts](https://github.com/netless-io/flat-server/blob/e6fdf472e9a91aff6302d3e2c4b8bbad19bce854/src/v2/services/developer/partner.ts#L70-L121) · [More projects using crypto-random-string →](https://dashboard.exa.ai/playground/search?q=crypto-random-string%20GitHub%20projects)

**Quickstart**

```javascript
import cryptoRandomString from 'crypto-random-string';

console.log(cryptoRandomString({ length: 16, type: 'url-safe' }));
```

From [readme.md](https://cdn.jsdelivr.net/npm/crypto-random-string@6.0.0/readme.md)

### @paralleldrive/cuid2

[GitHub](https://github.com/paralleldrive/cuid2) · [npm](https://www.npmjs.com/package/@paralleldrive/cuid2) · [Docs](https://github.com/ericelliott/cuid2#readme)

Generates identifiers and validates their format.

- Downloads / mo: 115.6M
- Stars: 3.4K
- Last release: 3.3.0
- License: MIT
- Capabilities: [From the @paralleldrive/cuid2 docs](https://github.com/ericelliott/cuid2#readme)

**Strengths**

- **Configures generated ID length.** Pass length to init when the default size does not fit.
- **Includes an ID validator.** Use isCuid to check a generated or supplied ID.

**Watch out for**

- **Creation order needs another field.** Store createdAt separately when records need chronological ordering.

```sh
npm install @paralleldrive/cuid2
```

**Quickstart**

```typescript
import { createId } from '@paralleldrive/cuid2';

console.log(createId());
```

From [README.md](https://cdn.jsdelivr.net/npm/@paralleldrive/cuid2@3.3.0/README.md) · [Find projects using @paralleldrive/cuid2 →](https://dashboard.exa.ai/playground/search?q=Projects%20using%20%40paralleldrive/cuid2%20for%20identifier%20generation%20and%20validation&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### uid

[GitHub](https://github.com/lukeed/uid) · [npm](https://www.npmjs.com/package/uid) · [Docs](https://github.com/lukeed/uid#readme)

Generates random unique IDs of a fixed length.

- Downloads / mo: 86.9M
- Stars: 665
- Last release: 2.0.2
- License: MIT
- Capabilities: [From the uid docs](https://github.com/lukeed/uid#readme)

```sh
npm install uid
```

**nestjs/nest** (77.1K stars)

[nestjs/nest](https://github.com/nestjs/nest) 

```javascript
export function mixin<T>(mixinClass: Type<T>) {
  Object.defineProperty(mixinClass, 'name', {
    value: uid(21),
  });
  // The class may declare a scope, on itself or on a class it extends, and
  // `@Injectable()` with no options would replace it with none
  Injectable(Reflect.getMetadata(SCOPE_OPTIONS_METADATA, mixinClass))(
    mixinClass,
  );
  // Decorated here, at runtime, so a compiler that emits decorator metadata may
  // have had no decorator to emit parameter types for. The injector can't take
  // that for a compiler that emits none.
  if (!Reflect.hasMetadata(PARAMTYPES_METADATA, mixinClass)) {
    Reflect.defineMetadata(PARAMTYPES_METADATA, [], mixinClass);
  }
  return mixinClass;
}
```

[packages/common/decorators/core/injectable.decorator.ts](https://github.com/nestjs/nest/blob/bbbfaf1765308826a581a75424a11d0f3e59521a/packages/common/decorators/core/injectable.decorator.ts#L57-L73) · [More projects using uid →](https://dashboard.exa.ai/playground/search?q=uid%20GitHub%20projects)

**Quickstart**

```javascript
import { uid } from 'uid';

console.log(uid());
```

From [readme.md](https://cdn.jsdelivr.net/npm/uid@2.0.2/readme.md)

### ulid

[GitHub](https://github.com/ulid/javascript) · [npm](https://www.npmjs.com/package/ulid) · [Docs](https://github.com/ulid/javascript#readme)

Generates lexicographically sortable identifiers containing a time component.

- Downloads / mo: 66.6M
- Stars: 3.4K
- Last release: 3.0.2
- License: MIT
- Capabilities: [From the ulid docs](https://github.com/ulid/javascript#readme)

**Strengths**

- **Maintains same-timestamp order.** Use monotonicFactory when IDs generated together must remain ordered.
- **Recovers the encoded timestamp.** Use decodeTime to read the timestamp stored in a ULID.

**Watch out for**

- **Canonical IDs have fixed length.** Use Nano ID when the ID length must be configurable.
- **IDs expose creation time.** The timestamp can be recovered with decodeTime.

```sh
npm install ulid
```

**Quickstart**

```typescript
import { ulid } from 'ulid';

console.log(ulid());
```

From [README.md](https://cdn.jsdelivr.net/npm/ulid@3.0.2/README.md) · [Find projects using ulid →](https://dashboard.exa.ai/playground/search?q=Projects%20using%20ulid%20for%20identifier%20generation%20and%20validation&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### @lukeed/uuid

[GitHub](https://github.com/lukeed/uuid) · [npm](https://www.npmjs.com/package/@lukeed/uuid) · [Docs](https://github.com/lukeed/uuid#readme)

Generates random UUIDs for Node.js and the browser.

- Downloads / mo: 33.2M
- Stars: 410
- Last release: 2.0.1
- License: MIT
- Capabilities: [From the @lukeed/uuid docs](https://github.com/lukeed/uuid#readme)

```sh
npm install @lukeed/uuid
```

**Quickstart**

```javascript
import { v4 } from '@lukeed/uuid';

console.log(v4());
```

From [readme.md](https://cdn.jsdelivr.net/npm/@lukeed/uuid@2.0.1/readme.md) · [Find projects using @lukeed/uuid →](https://dashboard.exa.ai/playground/search?q=%40lukeed/uuid%20GitHub%20projects)

### guid-typescript

[GitHub](https://github.com/snico-dev/guid-typescript) · [npm](https://www.npmjs.com/package/guid-typescript) · [Docs](https://github.com/NicolasDeveloper/guid-typescript#readme)

Generates GUIDs in TypeScript.

- Downloads / mo: 28.6M
- Stars: 54
- Last release: 1.0.9
- License: ISC
- Capabilities: [From the guid-typescript docs](https://github.com/NicolasDeveloper/guid-typescript#readme)

```sh
npm install guid-typescript
```

**SonarSource/sonar-scanner-azdo** (119 stars)

[SonarSource/sonar-scanner-azdo](https://github.com/SonarSource/sonar-scanner-azdo) 

```typescript
public static getDefaultPath() {
    return path.join(
      tl.getVariable("Agent.TempDirectory") as string,
      TaskReport.getDefaultPathTemplate().replace("<GUID>", Guid.create().toString()),
    );
  }
```

[src/common/latest/sonarqube/TaskReport.ts](https://github.com/SonarSource/sonar-scanner-azdo/blob/0232e6deb03860b7b172d68be9b5f609a4985c63/src/common/latest/sonarqube/TaskReport.ts#L78-L83) · [More projects using guid-typescript →](https://dashboard.exa.ai/playground/search?q=guid-typescript%20GitHub%20projects)

**Quickstart**

```typescript
import { Guid } from 'guid-typescript';

console.log(Guid.create().toString());
```

From [README.md](https://cdn.jsdelivr.net/npm/guid-typescript@1.0.9/README.md)

## FAQ

### Which JavaScript UUID library should I use?

[uuid](#uuid) suits code that needs standard UUIDs with parsing and validation. [nanoid](#nano-id) suits short, URL-safe IDs with a custom alphabet. [ulid](#ulid) suits IDs that sort by creation time.

### What is Nano ID?

[nanoid](#nano-id) generates short random string IDs from a URL-safe alphabet. Both the length and the alphabet are configurable.

### What is a UUID?

A UUID is a standard identifier written as hexadecimal digits in five groups separated by hyphens. Random UUIDs make collisions unlikely enough that systems generate them without coordination.

### ULID vs UUID: what is the difference?

A ULID starts with a timestamp followed by random characters. That prefix sorts ULIDs in creation order, unlike random UUIDs.

### CUID vs UUID: what is the difference?

[@paralleldrive/cuid2](#cuid) generates collision-resistant IDs that start with a letter and do not reveal their creation time. A UUID follows a standard format that databases and APIs recognize.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best JavaScript UUID and ID generation libraries uuid Nano ID ULID Cuid2 code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
