Categories
JavaScript Answers

How to generate unique ID with Node.js?

Spread the love

Sometimes, we want to generate unique ID with Node.js.

In this article, we’ll look at how to generate unique ID with Node.js.

How to generate unique ID with Node.js?

To generate unique ID with Node.js, we can use the uuid package.

For instance, we run

npm install uuid

Then we use it by writing

const {
  v1: uuidv1,
  v4: uuidv4,
} = require('uuid');

uuidv1();
uuidv4()

to call uuidv1 to return v1 UUID strings and call uuidv4 to return v4 UUID strings.

Conclusion

To generate unique ID with Node.js, we can use the uuid package.

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 *