Creating a User Database

Next step after my earlier experiments with MongoDB databases was to create a system where users could log on and view their step data from a pedometer. To do this I needed to make a database of users and store their data. To make the database I used Passport.JS a user authentication Node package which would create user sessions. This makes the user’s data more secure by hashing their passwords, so that they can’t be stolen easily.

project structure
The file structure of my project

As the project was going to be quite big, I decided to use Express.js which is a web framework for node. It automatically creates a web app file structure which saves time creating it from scratch. I also used Jade which is a html template engine, which means you can add variables to html more easily to pass through my data.

First off was to create my Mongoose model, with a user id, username, password and a logging system for past steps and the change in steps from yesterday to today.

Next was to create user sessions, by serializing and deserializing the user through passport. This creates a “logged on” state for the user.

This function checks if a user is registered in the system and tells them what is wrong if their username or password does not match any of the ones that are stored.



The sign in and registration page.

I also created pages for users to create a new profile, and a home page to view their information.



The home page

From the home page I created a method where users can input the number of steps they have walked that day.

Next I will look at different ways this data can be used., 2015. Passport. [online] Available from: [Accessed 28 Nov. 2015]., 2015. Express – Node.js web application framework. [online] Available from: [Accessed 28 Nov. 2015]., 2015. Jade – Template Engine. [online] Available from: [Accessed 28 Nov. 2015].