This repository contains sample code on how to use Redis for a cookie-based session implementation with Redis and the Node.js express framework.
This repository is part of the Sessions in express.js tutorial series on YouTube provided by productioncoder.com.
For updates, please reach out to @_jgoebel on Twitter.
This repository illustrates how to create a session-based authentication system in Express.js and what configurations you need to perform for you server to also accept cookies from cross origins - a scenario that is typical for Single Page Applications (SPAs) written in modern frameworks such as React or Vue.
Make sure that you have Redis running locally on your machine on its default port 6379
.
This project assumes that your Redis instance does not require a password (which is the default).
If your local Redis requires a password, please update the db/redis.js
file to include the password field:
const redisClient = redis.createClient({
port: 6379,
host: 'localhost',
password: 'your-password'
});
If you are on macOS, the easiest way to start up a Redis instance is by using Homebrew
brew install redis
brew services start redis
To stop Redis, you can run
brew services stop redis
Run:
npm install
to install the project's dependencies.
Execute the dev
script to start up your server.
npm run dev