JSON Web Token Authentication With Node.js

JSON Web Token Authentication With Node

Let’s now protect some endpoints by making use of JSON Web Tokens. What are JWTs? JSON web tokens are base64url encoded JSON Objects which are encrypted by the use of a private key. Embedded within the JWT can be one or more sets of name and value pairs. You might have things like a user id or user name embedded within the token. You can not see this data thanks to the encryption in place, but it can be deciphered on the server since the private key is available to the application.…

How To Add Routes and Models To Node Rest API

How To Add Routes and Models To Node Rest API

At the conclusion of our last tutorial which looks at working with Models in Mongoose, we now have a REST api which allows us to create new users and authenticate users. In a prior tutorial we also built out a restful resource for Games. In other words, we were able to create, read, update, and delete Games using the Node powered api. Now, we’ll once again go over the process of how routes files and model files work together in an express app.…

Information Expert Principle Applied To Mongoose Models

Adding a method to a Mongoose Model

In programming the Information expert, or the expert principle, is an approach used to determine where to delegate responsibilities. In other words, where should you place the code that completes specific tasks. The Information expert principle will help a developer to place the responsibility in the class with the most information required to fulfill it. In this tutorial we are going to clean up the process of generating JSON Web Tokens to make our code more clear and easier to maintain.…

Node.js MongoDB User Registration

mongodb user registration

So we are going to start building the most basic of User Registration systems in Node.js using MongoDB as the data store, Express as the routing system, Joi as the validator, and of course Mongoose to make interacting with Mongo from Node easy. Below we have our sample project layout. User-Registration is the top level directory which holds the index.js file, and then we have a models directory and a routes directory.…

Mongoose Relationships Tutorial

Mongoose Relationships Tutorial

NoSQL databases like MongoDB work differently than the older and more established Relational Databases like MySQL, Oracle, Microsoft SQL, and so on. Relationships in the traditional sense don’t really exist in MongoDB like they do in MySQL. In this tutorial we’ll take a look at how you can work with related data, even though it is not explicitly enforced by MongoDB. We’ll have a look at Reference Based Relationships (Normalization) as well as Embedded Documents Relationships (Denormalization).…