Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

For some reason a function I am calling 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?

like image 439
Jake Jackson Avatar asked Feb 20 '26 04:02

Jake Jackson


1 Answers

For all who is NodeJS and seeking for answer:

import * as crypto from 'crypto';
like image 56
Daniel Ray Avatar answered Feb 21 '26 17:02

Daniel Ray



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!