Flowstate is a Node.js middleware designed for managing and propagating per-request state across a sequence of HTTP requests within an Express or Connect application. It allows developers to implement 'flows' where state is maintained across multiple redirects and user interactions, culminating in a desired outcome. By default, it integrates with existing session middleware, isolating state for specific request sequences rather than global session state. State propagation relies on `return_to` and `state` query/body parameters, which the middleware automatically handles on redirects and exposes via `res.locals` for manual inclusion in views. The current and only stable version is 0.6.0, published in 2017. The package appears to be abandoned, with no releases or significant activity since that time, making it potentially incompatible with modern Node.js and Express versions.
npm install flowstateVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate flowstate middleware into an Express application, requiring `express-session` for state persistence. It shows how to initialize the middleware on a route, access per-request state via `req.state`, and manually propagate `return_to` and `state` parameters to a view using `res.locals` for subsequent requests.
Consider using alternative state management libraries, building custom middleware, or relying on modern framework features. Thorough testing with your current environment is essential if you must use it.
Ensure you have a compatible session middleware (e.g., `npm install express-session`) and configure it globally or on relevant routes before initializing `flowstate` middleware. Example: `app.use(session({ /* ... */ })); app.use(flowstate());`In your view templates, ensure that any links or forms meant to continue a flow include `return_to` and `state` query parameters or hidden inputs, populated from `res.locals`. For example: `<a href="/next?return_to=<%= returnTo %>&state=<%= stateParam %>">Continue</a>`.
Use CommonJS `require()` syntax: `const flowstate = require('flowstate');`. If integrating into an ESM project, consider dynamic import (`import('flowstate')`) or a transpilation step, though the abandoned status makes this generally unadvisable.Ensure `flowstate()` is called as a function `app.use(flowstate())`. Also verify that your Express version is compatible; given the package's age, very recent Express versions might have breaking changes.
Add a compatible session middleware, such as `express-session`, before `flowstate` in your middleware stack. Example: `app.use(require('express-session')({ secret: '...', resave: false, saveUninitialized: false })); app.use(flowstate());`Inspect your rendered HTML to ensure that `return_to` and `state` query parameters (for links) or hidden form fields (for forms) are present and populated with the values from `res.locals.returnTo` and `res.locals.state` (or `res.locals.stateParam`). Also, double-check your `express-session` configuration for proper setup.
No dependency data recorded yet.