Sometimes, we want to send flash messages in Express and JavaScript.
In this article, we’ll look at how to send flash messages in Express and JavaScript.
How to send flash messages in Express and JavaScript?
To send flash messages in Express and JavaScript, we use the connect-flash
package.
To install it, we run
npm i connect-flash
Then we use it by writing
const express = require("express");
const flash = require("connect-flash");
const app = express();
app.use(flash());
//...
app.all("/", (req, res) => {
req.flash("test", "it worked");
res.redirect("/test");
});
We add the flash
middleware with app.use
.
Then we send our flash message with req.flash
.
Conclusion
To send flash messages in Express and JavaScript, we use the connect-flash
package.