const bcrypt = require('bcrypt')
const hash = bcrypt.hash(<myPassword>, 12)
const hashSync = bcrypt.hashSync(<myPasword>, 12)
What aspects do they possibly differ in, and Could they be used interchangeably? (Detailed explanation very much welcome and greatly appreciated!)
hashSync is used to Synchronously generates a hash for the given string. It returns the hashed string
hash is used for Asynchronously generating a hash for the given string. It returns promise is callback is committed and you need to resolve the promise.
refer https://www.npmjs.com/package/bcryptjs#hashsyncs-salt
bcrypt.hash takes a callback as its third parameter which will be called when the hash is completed. bcrypt.hashSync runs the hash, waits for it to complete and returns the hashed value.
In other words "hash" is asynchronous and hashSync is synschronous.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With