Categories
JavaScript Answers

How to generate guid/uuid in TypeScript Node.js app?

Spread the love

To generate guid/uuid in TypeScript Node.js app, we use the uuid module.

For instance, we write

import { v4 as uuid } from "uuid";
const id: string = uuid();

to call the uuid function to return a uuid string.

We run

npm install uuid
npm install --save-dev @types/uuid

to install the uuid package and save the type definition for the package as a dev dependency.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *