Using Mongoose pre middleware to systematically hash a User
's password
const myuser = new User({
email: 'jdoe@hotmail.fr',
password: 'blacky123'
})
myuser.save()
.then(jdoe => {
console.log(jdoe.password) // $2b$10$nOUIs5kJ7naTuTFkBy1veuK0kSxUFXfuaOKdOKf9xYT0KKIGSJwFa
})
.catch(console.error)
cf. https://mongoosejs.com/docs/middleware.html#pre