npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@codecorn/connect-flash-new

v1.0.4

Published

Modern, type-safe Express flash middleware maintained by CodeCorn.

Readme

connect-flash-new

A modern, type-safe, and fully compatible flash messaging middleware for Express. This project is a clean reimplementation of the original connect-flash — actively maintained by the community, for the community.


✨ Features

  • 🔐 Safe flash message handling via session
  • 🧠 TypeScript-ready (.d.ts included)
  • ♻️ Fully compatible with CommonJS (require) and ES Modules (import)
  • 🧪 Easy to test (with supertest)
  • 🔥 Drop-in replacement for deprecated connect-flash

📦 Installation

npm install @codecorn/connect-flash-new

🚀 Usage

// ✅ ESM / TypeScript
import express from 'express';
import session from 'express-session';
import flash from '@codecorn/connect-flash-new';

// ✅ CommonJS (require)
const express = require('express');
const session = require('express-session');
const flash = require('@codecorn/connect-flash-new');

const app = express();

app.use(session({ secret: 'secret', resave: false, saveUninitialized: true }));
app.use(flash());

app.get('/', (req, res) => {
    req.flash('info', 'Welcome back %s!', 'Federico');
    res.send(req.flash('info'));
});

🧪 Testing with Supertest

// ✅ ESM
import request from 'supertest';
import express from 'express';
import session from 'express-session';
import flash from '@codecorn/connect-flash-new';

// ✅ CommonJS
const request = require('supertest');
const express = require('express');
const session = require('express-session');
const flash = require('@codecorn/connect-flash-new');

const app = express();
app.use(session({ secret: 'test', resave: false, saveUninitialized: true }));
app.use(flash());

app.get('/test', (req, res) => {
    req.flash('info', 'Test Message');
    res.json({ messages: req.flash('info') });
});

test('should return flash message', async () => {
    const res = await request(app).get('/test');
    expect(res.body.messages).toContain('Test Message');
});

🔐 Safe Init Helper (Optional)

If you want a one-liner to safely initialize both cookie-parser and connect-flash-new, you can use our helper:

const express = require('express');
const session = require('express-session');
const { safeFlashInit } = require('@codecorn/connect-flash-new/helpers');

const app = express();
app.use(session({ secret: process.env.SESSION_SECRET, resave: false, saveUninitialized: true }));

safeFlashInit(app); // Will use process.env.SESSION_SECRET or throw a warning

🧪 Experimental: flashMessages Middleware (Preview)

In alternativa al classico flash(), puoi usare flashMessages per accedere ai messaggi flash direttamente in res.locals.sessionFlash. Questa funzionalità è opt-in e può essere abilitata nel tuo .env o in modo programmatico:

// lib/flashMessages.js
import { flashMessages } from '@codecorn/connect-flash-new';

app.use(flashMessages);

🔧 Attivazione condizionata via .env

Puoi attivarlo dinamicamente leggendo da .env:

if (process.env.ENABLE_FLASH_MESSAGES === 'true') {
    app.use(flashMessages);
}

Questo middleware:

  • 🔄 Passa i messaggi da req.session.flash a res.locals.sessionFlash
  • 🧼 Svuota la sessione per evitare messaggi duplicati/zombie
  • 🛡️ Inizializza req.session.flash se mancante

⚠️ In fase sperimentale — potrà evolvere con il feedback della community.


🙏 Credits

Originally inspired by connect-flash by @jaredhanson.
This project continues the spirit of the original package, updated for modern Node.js and TypeScript environments.


👤 Maintainer