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 • Session Authentication in Express 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.
express-session https://www.npmjs.com/package/express...
connect-redis https://www.npmjs.com/package/connect...
Project repo https://github.com/alex996/node-auth
Watch video Authentication in Node.js - #2 Connecting to MongoDB & Redis online without registration, duration hours minute second in high quality. This video was added by user Code Realm 20 December 2019, don't forget to share it with your friends and acquaintances, it has been viewed on our site 25,51 once and liked it 34 people.