Is there an elegant way to return a bcrypt hash value to a separate module?
In the example below function hashPassword() uses bcrypt to hash a password. It is located in the file hashpassword.js. I'd like to return its hash value to the variable myHashedPassword in app.js. I'm sure there must be a brute force way to do this. But is there any sort of clever or elegant way to return the value?
app.js
let password = '123';
let myHashedPassword = hashPassword(password);
hashpassword.js
function hashPassword(password) {
bcrypt.genSalt(10, function(error, salt) {
bcrypt.hash(password, salt, function(error, hash) {
// In most cases at this point hash is saved to the database.
// However is there a pattern to return its value to the outer function and then app.js?
// With this being async is that even possible?
});
});
}