How to use 'crypto' module in Angular2?

前端 未结 4 687
无人及你
无人及你 2020-12-06 02:27

I install module:

npm install --save crypto

I import it to my component:

import { createHmac } from \"crypto\";
         


        
4条回答
  •  难免孤独
    2020-12-06 02:50

    To use crypto NodeJS library with Typescript (Angular >= 2 for example) follow these steps:

    1. npm install @types/node --save-dev to install NodeJS definitions
    2. In tsconfig.ts file add the following:

      "files": [ "./node_modules/@types/node/index.d.ts" ]

    3. Import the library where you want to use it with import * as crypto from 'crypto';

提交回复
热议问题