Broadway Application Extensibility

4.1.0 · abandoned · verified Wed Apr 22

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates initializing a Broadway `App`, mixing in Express.js, registering a `preboot` hook, defining basic Express routes, and starting the HTTP server.

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`).

view raw JSON →