Using bcrypt to encrypt a password

The next step is to make sure that the user's password will be encrypted when we store it on MongoDB. This process is really easy and only uses a new library, called bcrypt .

bcrypt is available at https://www.npmjs.com/package/bcrypt.

To use bcrypt, install it through npm:

$ npm install --save bcrypt

You also need to install the types:

$ npm install --save @types/bcrypt

Once you have installed bcrypt, as well as its types, change the 02_user.spec.ts file to create a new user on the before step, with the password encrypted:

...import * as bcrypt from 'bcrypt'...  before(async () => {    expect(UserModel.modelName).to.be.equal('User')    UserModel.collection.drop()    const newUser = new UserModel(user) newUser.password ...

Get Hands-On RESTful Web Services with TypeScript 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.