Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
NodeJS, crypto.randomUUID is not a function

I'm very new to JS, I want to generate an UUID. Here's what I tried, step by step:

  1. mkdir test
  2. cd test
  3. touch file1.js
  4. Inside file1.js:

let crypto;
try {
  crypto = require('crypto');
} catch (err) {
  console.log('crypto support is disabled!');
}


var uuid = crypto.randomUUID();
console.log(uuid);

And you see the error. What is wrong? I can't find answer anywhere. Node JS version:

node -v shows v12.22.9

enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

here you can use randomBytes() method for get unique id

const crypto = require('crypto');
console.log(crypto.randomBytes(20).toString('hex'));

you can also use uuidv4 instead of crypto

const { uuid } = require('uuidv4');
console.log(uuid());
about 4 years ago · Juan Pablo Isaza Report

0

I upgraded NodeJS to newer version, and it worked!

I had some problems, so I tried to remove NodeJS (I had the same problem like this guy: https://github.com/nodesource/distributions/issues/1157).

And installed LTS version: https://askubuntu.com/questions/1265813/how-to-update-node-js-to-the-long-term-support-version-on-ubuntu-20-04.

Now I have:

node -v v16.16.0

and script works! Thank you :)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!