Finishing the Application

Back to actions.registerUser, we have two steps left. hashPassword and writeRegisterCommand. Here is hashPassword:

 const​ bcrypt = require(​'bcrypt'​)
 
 // We could pull this out into an environment variable, but we don't
 const​ SALT_ROUNDS = 10
 function​ hashPassword (context) {
 return​ bcrypt
  .hash(context.attributes.password, SALT_ROUNDS)
  .then(passwordHash => {
  context.passwordHash = passwordHash
 
 return​ context
  })
 }
 
 module.exports = hashPassword

It uses bcrypt[49] to hash the password and attaches the hash at context.passwordHash.

Now that everything has checked out, we can finally write the command:

Get Practical Microservices now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.