Learn

In order to implement sessions within an Express application, we can use the NPM module, express-session, as a middleware.

Once the session middleware is implemented, each user that navigates to our app will have a unique session generated for them. This allows us to store their session data server-side under a session identifier and easily retrieve it.

We can install the package by running the following command:

npm install express-session

From here, we import the session module and store it in a variable:

const session = require("express-session")

Instructions

1.

Install the package express-session using the terminal.

Click on Check Work after installing.

2.

Import the express-session module and store it in a variable called session.

Click on Check Work after installing.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?