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

340
Views
Node.js crypto.randomBytes() is not a function

For some reason a function I am trying to use is, apparently, not a function.

Welcome to Node.js v14.15.1.
Type ".help" for more information.
> const crypto = require("crypto");
undefined
> x = crypto.randomBytes(32).toString("hex")
Uncaught TypeError: crypto.randomBytes is not a function

Documentation for randomBytes().

Is there something I am not understanding?

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

0

Seems getRandomBytes() function got removed. I read some disclaimers that it is not very secure.

https://www.npmjs.com/package/crypto is clustured with deprecation messages so altough most upvotes here under https://stackoverflow.com/a/8856177/828184 it does no longer seem state of the art to me.

Before I could simply use (like you but no longer after package updates)

import crypto from "crypto";
const token = crypto.randomBytes(64).toString('hex');

But crypto now only has getRandomValues() and I think it is not a replacement.

Only answer nr 3 with also a lot but not as many upvotes gave me a working version https://stackoverflow.com/a/25690754/828184. So maybe also try:

import { nanoid } from "nanoid";
const token = nanoid(64); //instead of crypto.randomBytes(64).toString('hex')

And leave an upvote there if it works because.

about 4 years ago · Juan Pablo Isaza Report

0

If you attemped to create a token.

You can just type the following command in your nodejs cli:

crypto.randomBytes(64).toString('hex');

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!