As found in this SO-answer, the following thing could be a way how to encrypt a password into a hash:
@BeforeInsert() async hashPassword() {
this.password = await bcrypt.hash(this.password, Number(process.env.HASH_SALT));
}
However, although I have installed "bcrypt" and "types/bcrypt", it can't get found by NodeJS:
src/entities/user.entity.ts:50:27 - error TS2552: Cannot find name 'bcrypt'. Did you mean 'crypto'?
In my package.json the following lines show that bcrypt was successfully installed:
"@types/bcrypt": "^5.0.0",
"bcrypt": "^5.0.1",
How to fix this?
Import the bcrypt on the files where you use it like this:
import * as bcrypt from 'bcrypt';