Is there a way to generate random UUID like the ones used in CouchDB but with Node.js?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are different ways to generate UUIDs. If you are already using CouchDB, you can just ask CouchDB for some like this:
CouchDB has three different UUID generation algorithms. You can specify which one CouchDB uses in the CouchDB configuration as uuids/algorithm. There could be benefits to asking CouchDB for UUIDs. Specifically, if you are using the “sequence” generation algorithm. The UUIDs you get from CouchDB will fall into that sequence.
If you want to do it in node.js without relying on CouchDB, then you’ll need a UUID function written JavaScript. node-uuid is a JavaScript implementation that uses “Version 4” (random numbers) or “Version 1” (timestamp-based). It works with node.js or hosted in a browser: https://github.com/broofa/node-uuid
If you’re on Linux, there is also a JavaScript wrapper for libuuid. It is called uuidjs. There is a performance comparison to node-uuid in the ReadMe of node-uuid.
If you want to do something, and it doesn’t look like it’s supported in node.js, be sure to check the modules available for npm.