Open harmnot opened 5 years ago
Same here
Whats the error? You installed flash?
npm install -S connect-flash
and in app.js
const flash = require('connect-flash')
In the app.js file, you added the middleware?
// connect flash middleware
app.use(flash())
// global variables. Creating our own middleware. Custom middleware coming from flash
app.use((req, res, next) => { // color code the message type
res.locals.success_msg = req.flash('success_msg')
res.locals.error_msg = req.flash('error_msg')
res.locals.error = req.flash('error')
next()
})
All flash does is stores the message in the cookie, so when you get redirected to another page, it has that message to display
Seems, the problem is located in the messages.ejs file.
@inspiretk I am running into the error throw new TypeError('app.use() requires a middleware function') ^
TypeError: app.use() requires a middleware function at Function.use
I literally copy pasted these files but still this error is there
Did you install it? You supposed to clone the whole project, then install all the requirements: npm install.
I havn't used this for a long time, so I don't follow it anymore, but when I did it, it worked fine
Follow the tutorial video again, it should work. In the console log, sometimes it tells you which file and line the error is, pay attention to that part and see.
@inspiretk thanks for your response but I found out what the error was and thought of mentioning it here I mistakenly installed 'express-sessions' which is the wrong package it is 'express-session' instead without the s
Same here. Not working
I found what my error was and resolved it. I used a wrong reference success_messasges instead of success_msg
I fixed this by removing the cookie property
app.use(session({
secret:'secret',
saveUninitialized: true,
resave: true
}));
instead of this:
app.use(session({
secret: 'secret',
resave: false,
saveUninitialized: true,
cookie: { secure: true }
}));
You can put it back when you deploy your application to production
I follow your instructions but I failed on req.flash, is that flash method return array?