express.js: show toastr message
<p>I'm trying to get Toastr library to work in my ExpressJS app! I scaffolded the app with the yeoman 'standard' Express Generator...</p>

<p>I've required the lib <code>express-toastr</code> and did the following:</p>

<p>in <code>app.js</code>:</p>

<pre><code>const cookieParser = require('cookie-parser');
const session = require('express-session');
const flash = require('connect-flash');
const toastr = require('express-toastr');

app.use(cookieParser());
app.use(session( {secret: 'xxx', saveUninitialized: true, resave: true} ));
app.use(flash());
app.use(toastr());
</code></pre>

<p>in <code>index.js</code></p>

<pre><code>const express = require('express');
const router = express.Router();
const httpntlm = require('httpntlm');

router.post('/', function (req, res, next) {

    // parse inputs
    let user = req.body.user || "";
    let password = req.body.password || "";

    // save in session
    req.session.user = {user: user, password: password};

    // appropriate response to login attempt
    if (!req.session.user) {
        res.status(401).send();
    }
    else {
        req.toastr.success('Successfully logged in.', "You're in!");

        res.render('groups', {
            req: req
        });
    }
});

module.exports = router;
</code></pre>

<p>In <code>index.jade</code></p>

<pre><code>#{req.toastr.render()}
</code></pre>

<p>I'm loading these files in my <code>&lt;head&gt;</code> section:</p>

<pre><code>link(rel='stylesheet', href='//cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.2/css/toastr.min.css')
script(src='/components/jquery/dist/jquery.min.js')
script(src='//cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.2/js/toastr.min.js')
</code></pre>

<p>Nothing is showing. What am I missing???</p>

<p><strong>-- UPDATE! --</strong></p>

<p>Here is my complete app.js file. I now try to use express-flash and making a dedicated route for showing a flash message. Still not working. Please help!</p>

<pre><code>'use strict';

const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');

const expressSanitizer = require('express-sanitizer');

const login = require('./routes/login');
const apply = require('./routes/apply');
const admin = require('./routes/admin');

var session = require('express-session');
var flash = require('express-flash');


var app = express();


// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));






app.use(session({
    cookie: { maxAge: 60000 },
    store: new session.MemoryStore,
    saveUninitialized: true,
    resave: 'true',
    secret: 'secret'
}));
app.use(flash());

// Route that creates a flash message using the express-flash module
app.all('/express-flash', function( req, res ) {
    req.flash('success', 'This is a flash message using the express-flash module.');
    res.redirect(301, '/');
});







// sanitize inputs
app.use(expressSanitizer());

app.use('/', apply);
app.use('/apply', apply);
app.use('/login', login);
app.use('/admin', admin);


// catch 404 and forward to error handler
app.use(function (req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
    app.use(function (err, req, res, next) {
        res.status(err.status || 500);
        res.render('error', {
            message: err.message,
            error: err
        });
    });
}

// production error handler
// no stacktraces leaked to user
app.use(function (err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
        message: err.message,
        error: {}
    });
});

module.exports = app;
</code></pre>