Broadway Application Extensibility
Broadway is a lightweight library designed for adding extensibility and hookable middleware customization to server applications. The current stable version is 4.1.0, though it was last published over eight years ago, indicating it is an abandoned project with no active release cadence. Its core differentiator is its minimal footprint and generic 'hook' mechanism, powered by the `understudy` library, which allows developers to inject custom logic into application lifecycle events and middleware chains. It is primarily intended for use with CommonJS modules and older Node.js environments (specifically requiring Node.js 8 or higher). While it demonstrates integration with frameworks like Express, it offers a foundational, unopinionated approach to modular application design through its `mixin` and `perform` capabilities.
Common errors
-
ReferenceError: require is not defined
cause Attempting to import `broadway` using ESM syntax (`import App from 'broadway';`) in a context where `require` is not globally available (e.g., in an ESM module without a compatibility layer).fixEnsure you are using CommonJS `require` syntax: `const App = require('broadway');`. -
TypeError: App is not a constructor
cause This error can occur if you're trying to instantiate `broadway` directly (e.g., `new broadway()`) instead of the exported `App` class, or if the import failed.fixConfirm your import statement is `const App = require('broadway');` and you are instantiating it as `new App(...)`. -
Error: Cannot find module 'broadway'
cause The `broadway` package has not been installed or is not accessible in the current project's `node_modules`.fixRun `npm install broadway` or `yarn add broadway` in your project directory.
Warnings
- breaking The `broadway` package requires Node.js >= 8, which is an extremely old and End-of-Life (EOL) version of Node.js. Using this package with modern Node.js versions may lead to compatibility issues or security vulnerabilities due to its abandoned status and outdated dependencies.
- gotcha Broadway is an abandoned project, with no updates in over eight years. This means there will be no future bug fixes, security patches, or feature enhancements. Dependencies may also be outdated and contain known vulnerabilities.
- gotcha The package is published exclusively as a CommonJS module. It does not provide ESM (ECMAScript Module) exports, and attempting to `import` it will result in `ReferenceError: require is not defined` in ESM-only contexts or other import resolution errors.
Install
-
npm install broadway -
yarn add broadway -
pnpm add broadway
Imports
- App
import App from 'broadway';
const App = require('broadway'); - App instance methods (e.g., mixin, preboot, start)
broadway.mixin(express());
app.mixin(express());
Quickstart
const express = require('express');
const App = require('broadway');
// Create a new base App instance, configuring it for an HTTP port.
// Mix in Express functionality directly during instantiation.
const app = new App({ http: 8080 }, express());
// Register a preboot hook to run logic before the application fully starts.
app.preboot(function (appInstance, options, next) {
console.log('Broadway application is starting up...');
// Simulate an async operation
setTimeout(() => {
console.log('Preboot hook finished.');
next();
}, 100);
});
// Define a basic route using the mixed-in Express functionality.
app.use((req, res, next) => {
if (req.url === '/') {
res.end('Hello from Broadway powered by Express!');
} else {
next();
}
});
app.use((req, res) => {
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('404 Not Found');
});
// Start the application and begin listening for HTTP requests.
app.start(function (err) {
if (err) {
console.error('Error on startup: %s', err.message);
return process.exit(1);
}
console.log('Listening over HTTP on port %s', this.given.http);
});
// To run this, save as app.js and run `node app.js`. Make sure express is installed (`npm i express broadway`).