How to Generate UUIDs with npm

Install UUID support with npm when you want one package interface for UUID v4 and UUID v7 across JavaScript and TypeScript projects.

Recommendation: use npm when you want one package that works in frontend and backend JavaScript or TypeScript projects.

How to install UUID support with npm

npm install uuid

How to generate UUID v4 with an npm package

import { v4 as uuidv4 } from 'uuid';

const id = uuidv4();
console.log(id);

How to generate UUID v7 with an npm package

import { v7 as uuidv7 } from 'uuid';

const id = uuidv7();
console.log(id);

Native support notes

  • npm only distributes packages. Generation happens inside your runtime.
  • The uuid package is a common choice when you want the same API across environments.
  • Be explicit about ESM vs CommonJS usage in project documentation.

Practical notes

  • Use npm package-based generation when runtime support is inconsistent.
  • Prefer native crypto.randomUUID() if you only need v4 and want fewer dependencies.
  • See the Node.js guide and the JavaScript guide for runtime-specific examples.

Frequently Asked Questions

No. npm installs a package, and your application runtime executes the actual UUID generation code.

The package gives you one consistent API and covers UUID versions such as v7 that are not usually native.

Learn more

These articles expand on related concepts, formats and practical considerations.

By using this site, you agree to our Privacy Policy and Terms of Service. You are not permitted to use the GUIDs (also known as UUIDs) generated by this site or use any other content, services and information available if you do not agree to these terms.
Disclaimer: All information is provided for general educational and technical reference only. While we aim to keep the content accurate, current and aligned with published standards, no guarantees are made regarding completeness, correctness or suitability for any specific use case.
GUID specifications, best practices, security guidance, database behavior and ecosystem conventions (including cloud platforms and identifier formats) may change over time or differ by implementation. Examples, recommendations and comparisons are illustrative and may not apply universally.
This content should not be considered legal, security, compliance or architectural advice. Before making critical design, security or production decisions, always consult the latest official standards and vendor-specific documentation.
Always evaluate behavior in your own environment.
Standards Compliance: The GUIDs generated by this site conform to RFC 4122 and RFC 9562 specifications whenever possible, using cryptographically secure random number generation.