Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

343
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda