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.
├── connect-flash@0.1.0 ├── ejs@0.8.3 ├── ejs-locals@0.2.5 ├─┬ express@3.0.0 │ ├── commander@0.6.1 │ ├─┬ connect@2.6.0 │ │ ├── bytes@0.1.0 │ │ ├── formidable@1.0.11 │ │ ├── pause@0.0.1 │ │ ├── qs@0.5.1 │ │ └─┬ send@0.0.4 │ │ └── mime@1.2.6 │ ├── cookie@0.0.4 │ ├── crc@0.2.0 │ ├── debug@0.7.0 │ ├── fresh@0.1.0 │ ├── methods@0.0.1 │ ├── mkdirp@0.3.3 │ ├── range-parser@0.0.4 │ └─┬ send@0.1.0 │ └── mime@1.2.6 ├─┬ passport@0.1.12 │ └── pkginfo@0.2.3 ├─┬ passport-local@0.1.6 │ ├── passport@0.1.12 │ └── pkginfo@0.2.3 ├─┬ socket.io@0.9.10 │ ├── policyfile@0.0.4 │ ├── redis@0.7.2 │ └─┬ socket.io-client@0.9.10 │ ├─┬ active-x-obfuscator@0.0.1 │ │ └── zeparser@0.0.5 │ ├── uglify-js@1.2.5 │ ├─┬ ws@0.4.22 │ │ ├── commander@0.6.1 │ │ ├── options@0.0.3 │ │ └── tinycolor@0.0.1 │ └── xmlhttprequest@1.4.2 └─┬ stylus@0.30.1 ├── cssom@0.2.5 ├── debug@0.7.0 └── mkdirp@0.3.4
Try adding this to your main app.configure method
app.use(flash());
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('/');