1.0.0 • Published 4 years ago

smz-flash v1.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

Flash data for Express.js

Express middleware that allows you to store data in the session that will be available only for the next request

Usage

npm i smz-flash
// index.js

const express = require("express");
const session = require("express-session");
const flash = require("smz-flash");

const app = express();

app.use(
  session({
    // options
  })
);

app.use(flash);

// ...
// controller.js

controller.doSmth = (req, res) => {
  if (sthBadHappens) {
    req.flash.error = "Something bad happened";
    res.redirect("back");
  }
};
// next-request-controller.js

controller.showSmth = (_, res) => {
  res.render("myView");
};
// myView.ejs

<% if(locals.error) { %>
  <p><%= error %></p>
} %>
1.0.0

4 years ago