Authentication in Node.js - #2 Connecting to MongoDB & Redis

Authentication in Node.js - #2 Connecting to MongoDB & Redis

In this video, we will wire up our application to MongoDB and Redis. We will also configure Express sessions and set up configuration files with environment ...

In this video, we will wire up our application to MongoDB and Redis. We will also configure Express sessions and set up configuration files with environment variables. Be sure to watch the previous video (especially, the latter half) so that you have the requisite project structure in place.

The default in-memory store in express-session leaks memory and doesn't scale beyond a single process, and as such, is not suitable for production. Two popular session stores are Redis and MongoDB, Redis being the logical choice due to its built-in support for self-expiring keys. You can use MongoDB instead, but you'd need to clean up expired sessions manually (for example, using a background job or request lottery).

If you've seen my Session Authentication in Express https://youtu.be/OH6Z0dJ_Huk video, it's based on version 3 of connect-redis. Version 4 no longer ships with a Redis client. You can install node-redis as before, or switch to ioredis for better maintenance and more features (including support for connection pools, for example).

In the past, you might've seen me use a single config file to export all environment variables. As the projects grows in size, so does its scope. In the long run, you'll find it more manageable to classify variables by their concern, i.e. database, cache, session, etc. This is the same pattern you will find in frameworks such as Laravel and Rails.

If you follow along til the end, you'll find that we can't boot our REST API just yet. We'll continue provisioning a dev environment with a database and a cache in the next episode. See you then.

mongodb redis

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Redis Transactions & Long-Running Lua Scripts

Redis Lua scripting is the popularly recommended approach for handling transactions. Learn the common Lua Scripts error and how to handle for sentinel systems. Redis offers two mechanisms for handling transactions – MULTI/EXEC based transactions and Lua scripts evaluation. Redis Lua scripting is the recommended approach and is fairly popular in usage.

MongoDB Database and java applications

Enroll for free demo to acquire the best knowledge on the schema-less database from live industry experts through MongoDB training

Which is the Best MongoDB GUI?

Our MongoDB Online Training provide you to learn about MongoDB strategies with realty. Our MongoDB Online Training also includes live sessions, live Projects, and much

Improve the MongoDB Aggregation Framework

Our MongoDB Online Training provide you to learn about MongoDB strategies with realty. Our MongoDB Online Training also includes live sessions, live Projects, and much

MongoDB – Database, Collection, and Document

Our MongoDB Online Training provide you to learn about MongoDB strategies with realty. Our MongoDB Online Training also includes live sessions, live Projects, and much