We're live-coding on Twitch! Join us!

In order to save messages (success or error) and display them on the client, since we are creating a round-trip application, we will need to use sessions. We'll need:

  • express-session: Give us the ability to create sessions in Node so that we can store data.
  • cookie-parser: Give us the ability to read those sessions that are stored in cookies.
  • connect-flash: Let us save messages to flash-data (one-time use messages) which we'll display as success/error messages.

Install all three packages with:

npm install --save express-session cookie-parser connect-flash

Then we can configure in server.js:

var session        = require('express-session'),
  cookieParser   = require('cookie-parser'),
  flash          = require('connect-flash');

// set sessions and cookie parser
  secret: process.env.SECRET, 
  cookie: { maxAge: 60000 },
  resave: false,    // forces the session to be saved back to the store
  saveUninitialized: false  // dont save unmodified

Like this article? Follow @chrisoncode on Twitter