If we want to maintain the state between page requests, we use sessions. Express supplies middleware that takes much of the complexity out of managing sessions. In this recipe, we're going to use Express to make a session between a browser and server to facilitate a user login process.
Let's create a fresh project:
This will create a new Express skeleton named
Let's move into the
login folder and run the following commands:
npm install email@example.com --save npm install method-override @1.x --save
These are both pieces of Express middleware, which we'll use in our new login app.
We need to add some lines to
app.js. First, where we require the dependencies, let's ...