Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using crypto module in Typescript

in my typescript project I'm trying to get SHA1 Hash with the help of crypto module from nodejs.

import crypto from 'crypto';

console.log(crypto.createHash('sha1').update('message').digest('hex'));

but after running it, the only thing I get is

TypeError: Cannot read property 'createHash' of undefined

What am I missing? Is there a better way to get SHA1 hash in typescript?

like image 879
BranTheBroken Avatar asked Oct 29 '25 20:10

BranTheBroken


1 Answers

Change the import line to:

import * as crypto from 'crypto';
like image 90
Balastrong Avatar answered Oct 31 '25 11:10

Balastrong