Episode 5 – Creating Models in Koajs

Author: James Moore

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.

Free Courses

Functional Concepts in JavaScript with Ramda

What's Ramda?

In this free mini-course, you'll learn about functional programming concepts like: map, filter, reduce, curry and function composition.

This is a great course for dipping your toes into Functional Programming.

Price:Free ($0)
Sign Up

Elm for Beginners

What's Elm, and why should I care?

It's an amazing language for writing web apps which have no runtime exceptions.

I'm pretty sure learning Elm will change the way you program And It's Free!

Price:Free ($0)
Sign Up