Skip to content

middleware to handle flash messages in Express.

Notifications You must be signed in to change notification settings

mediocre9/flashy.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Flashy

Simple middleware for handling flash messages in Express.

Usage

import express from "express";
import session from "express-session";
import { flashy } from "./flashy.js";

app.use(
    session({
        secret: "krabby patty secret formula",
        resave: false,
        saveUninitialized: true,
    })
);

app.use(flashy());

app.get("/", (request, response) => {
    request.flashy("success", " \(^0^)/ ");
    request.flashy("warning", " (˚☐˚! ) ");
    request.flashy("error", " (ⅈ▱ⅈ) ");
    response.redirect("/flashy");
});

app.get("/flashy", (request, response) => {
    // use any template engine
    const successNotifications = request.flashy("success");
    const warningNotifications = request.flashy("warning");
    const errorNotifications = request.flashy("error");
    response.render("template", {
        success: successNotifications,
        warning: warningNotifications,
        error: errorNotifications,
    });
});

app.listen(8080);

About

middleware to handle flash messages in Express.

Topics

Resources

Stars

Watchers

Forks