Episode 5 – Creating Models in Koajs

In this episode we will learn to create models in koajs, more specifically we'll create a user model.

First we'll create a package.json file to store our metadata using npm init.

When coding we will use a Test First approach to create our user model, using mochajs.

Then we'll use RethinkDB as we did in the last episode to store our user records.

To create our database and users table we'll create migrations using the npm package migrate.

Then we'll avoid committing a BIG developer SIN (storing passwords in clear text) by using bcrypt to properly hash our users passwords.

When we implement the password hashing we'll use the Object.defineProperty method a cool way to create properties that have "getter" and "setter" methods... except we get to use them with simpler dot notation... user.password = 'mysecret'

Lastly we'll look at how to authenticate a user after hashing their password with bcrypt.