Create a CRUD App with Node and MongoDB: Lesson 14 of 17

Showing Success Messages

Up Next

Validation Error Messages

Autoplaying in 7 seconds!


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:

Table of Contents

    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

    Chris Sevilleja

    176 posts

    Founder of Google Developer Expert in Web Technologies. Slapping the keyboard until something good happens.