sequelize.jsModify attributes in beforeCreate hook


Introduction

We might need to modify the attributes before record is created. My use case was encrypting password when user is created.

Hooks doc is here http://docs.sequelizejs.com/en/v3/docs/hooks/#instance-hooks. It documents the way to use it with a library / function that returns a Promise. But the use case with a callback is not clearly documented.

Syntax

  • beforeCreate(instance)
  • beforeCreate(instance, options, fn)