broccoli-middleware is a utility that integrates the Broccoli asset pipeline's build output into standard Node.js HTTP servers, typically for development environments. It allows applications, especially those built with Ember CLI, to serve dynamically built assets through middleware like Express. The package is currently at version 2.1.1, with its last publication dating back to 2019. Its development is effectively abandoned, with no recent releases or active maintenance. It differentiates itself by providing a direct bridge between the Broccoli build process and a web server's request-response cycle, allowing for on-the-fly serving of compiled assets without a separate build step before server startup. This contrasts with build tools that pre-build all assets to a /dist folder.
npm install broccoli-middlewareVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `broccoli-middleware` with an Express server to serve assets from a simulated Broccoli build output directory. It shows basic integration for `app.js` and `styles.css`.
Consider migrating to modern asset bundling solutions like Webpack, Rollup, Parcel, or esbuild, which offer active maintenance and better compatibility. For Ember projects, leverage the built-in Ember CLI asset pipeline.
Ensure your project is configured for CommonJS or use dynamic `import()` if absolutely necessary within an ESM file (e.g., `const broccoliMiddleware = await import('broccoli-middleware');`). The preferred solution is to use `require` in a CJS file.For new projects or migrations, evaluate contemporary build tools (e.g., Vite, Webpack, Parcel) and their native development servers or middleware integrations.
Rename your file to `.cjs` or ensure `"type": "commonjs"` is set in your `package.json`. If using an ES module, consider dynamic import: `const broccoliMiddleware = await import('broccoli-middleware');` or refactor the consuming code to use a CJS wrapper.Ensure your session middleware (e.g., `express-session`) is configured with a `secret` option, for example: `app.use(session({ secret: process.env.SESSION_SECRET || 'a-very-secret-key', ... }));`.