/nest-bcrypt

Primary LanguageTypeScriptMIT LicenseMIT

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Support us

Description

Bcrypt Module for Nest.

Installation

$ npm install nest-bcrypt

Usage

Injecting the BcryptModule

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { BcryptModule } from 'nest-bcrypt';

@Module({
  imports: [BcryptModule.register({ salt: 10 })],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Using the BcryptService

import { Injectable } from '@nestjs/common';
import { BcryptService } from 'nest-bcrypt';

@Injectable()
export class AppService {
  constructor(private readonly bcryptService: BcryptService) {}

  public async hashData(data: string) {
    // return this.bcryptService.hash(data, _customSalt) // to use a custom salt different from that set
    return this.bcryptService.hash(data);
  }
}

Stay in touch

License

nest-bcrypt is MIT licensed.