Set individualHooks to true when bulkCreating as shown below:
User.bulkCreate(users, {individualHooks: true}).then(function() { console.log("Done!"); });
There is some (but not enough) documentation about this option here .
In addition, if you allow users to change passwords, you must add beforeUpdate hook. You can prevent bcrypt from being processed with the password twice (when the properties of a user other than the password are updated) as follows:
function hashPassword(user, options, fn) { //Don't hash if password is already hashed if (user.dataValues.password.indexOf('$2a$') === 0) { fn(null, user); return; } bcrypt.hash(user.password, 10, function(err, hash) { if (err) { console.log('Error while generating hash!'); fn(err, null); return; } user.password = hash; fn(null, user); }); }
source share