---
source_url: https://www.pubnub.com/docs/serverless-sdk/modules-and-libraries/uuid
title: uuid
updated_at: 2026-09-30T07:20:08.000Z
---

# uuid

## Documentation index

To discover more PubNub resources:

1. Fetch [PubNub's llms.txt](https://www.pubnub.com/llms-full.txt) for a list of available pages in Markdown format.
2. Identify relevant URLs from that index.
3. Fetch the target pages.

Do not assume a path exists, always check the index first.

The `uuid` built-in module is available only inside a PubNub Function. It generates and validates RFC-compliant universally unique identifiers (UUIDs).

```javascript
const { v3, v4, v5, validate, version } = require('uuid');
```

| Method | Signature | Returns |
| --- | --- | --- |
| `v3` | `v3(name, namespace)` | UUID string derived from the MD5 hash of `namespace` and `name`. |
| `v4` | `v4()` | Random UUID string. Requires no arguments. |
| `v5` | `v5(name, namespace)` | UUID string derived from the SHA-1 hash of `namespace` and `name`. |
| `validate` | `validate(str)` | `true` if `str` is a valid UUID, otherwise `false`. |
| `version` | `version(str)` | The RFC version number of UUID `str`. |

```javascript
const { v4, validate, version } = require('uuid');

export default req => {
    const uuid = v4();
    return req.ok({
        v4: uuid,
        valid: validate(uuid),
        version: version(uuid),
    });
};
```

## Related reference

* [Modules and libraries](https://www.pubnub.com/docs/serverless-sdk/modules-and-libraries/overview.md). Every built-in module available inside a Function.

Last updated at: 2026-09-30T07:20:08.000Z
