Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

341
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda