2
votes

I'm new to NodeJS and trying to build an app over Express3.0, included passport local strategy for authentication purpose. But the following exception(with respect to req.flash) blocks my progress.

Exception occurs in the following line.
res.render('login', { user: req.user, message: req.flash('error') });
Express
500 TypeError: Object # has no method 'flash'

    at /Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/app.js:115:54
    at callbacks (/Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/lib/router/index.js:162:37)
    at param (/Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/lib/router/index.js:136:11)
    at pass (/Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/lib/router/index.js:143:5)
    at Router._dispatch (/Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/lib/router/index.js:171:5)
    at Object.router (/Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/lib/router/index.js:33:10)
    at next (/Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at store.get.next (/Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/node_modules/connect/lib/middleware/session.js:310:9)
    at /Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/node_modules/connect/lib/middleware/session.js:333:9
    at /Users/vivekanandan/Source/Git/ExpressApp/CosmicEnergyCoupled/node_modules/express/node_modules/connect/lib/middleware/session/memory.js:52:9


I have installed connect-flash to recover the deprecated req.flash method as advised by the author(passport-local-strategy). Please find the npm packages installed in the app.

├── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └─┬ [email protected]
│ │   └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│   └── [email protected]
├─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│   ├─┬ [email protected]
│   │ └── [email protected]
│   ├── [email protected]
│   ├─┬ [email protected]
│   │ ├── [email protected]
│   │ ├── [email protected]
│   │ └── [email protected]
│   └── [email protected]
└─┬ [email protected]
  ├── [email protected]
  ├── [email protected]
  └── [email protected]
2

2 Answers

0
votes

Try adding this to your main app.configure method

app.use(flash());
0
votes
npm install connect-flash --save

var flash = require('connect-flash')
app.use(flash());

You're using it wrong I think. You just have to call req.flash() with type and message before res.redirect

   req.flash('info', 'Welcome to the site, a welcome email has been sent to you.');
   res.redirect('/');