Registry / http-networking / common-middleware

common-middleware

JSON →
library1.0.0jsnpmunverified

common-middleware is a JavaScript utility library that provides a collection of reusable middleware functions designed for applications built upon the `base-methods` framework, particularly for projects like Assemble, Verb, Generate, and Update. It currently stands at version 1.0.0, last updated over two years ago, indicating a maintenance phase rather than active development. The library focuses on processing file objects in a pipeline, offering functionalities such as front-matter parsing, escaping and unescaping template delimiters, and managing JSON data on load and pre-write. Its key differentiator is its integration within the `base` and `assemble` ecosystem, providing standardized pre-processing capabilities for file-based templating and content management workflows common in static site generators or documentation builders. It is specifically designed for Node.js environments, historically supporting versions `0.10.0` and above, and primarily uses CommonJS modules.

npm install common-middleware
INSTALL
IMPORT
SIG · COMMON-MIDDLEWARE
C
common-middleware
http-networkingjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

middleware
const middleware = require('common-middleware');
import middleware from 'common-middleware';
This package is primarily a CommonJS module. Direct ESM `import` syntax is not supported without a transpilation step or a CommonJS wrapper.

This quickstart demonstrates how to initialize `common-middleware` and register its suite of file processing functions with an `assemble-core` application. Once registered, it automatically handles tasks like front-matter parsing, template escaping, and JSON file processing within the application's file pipeline.

const middleware = require('common-middleware'); const assemble = require('assemble-core'); // Install via: npm install assemble-core // Create your application instance (e.g., from assemble-core, verb, generate) const app = assemble(); // Register the common middleware suite with the application. // This attaches the various hooks (onLoad, preWrite, etc.) to the app's lifecycle. app.use(middleware()); console.log('common-middleware registered with the application.'); // Now, as files are processed by 'app' (e.g., through app.src(), app.render(), app.dest()), // this middleware will automatically intervene to perform tasks like: // - Parsing YAML/JSON front-matter from files into `file.data` // - Escaping or unescaping template delimiters (e.g., `<%= foo %>`) // - Handling JSON parsing and stringifying for files matching `options.jsonRegex` // Example of how options can be passed (optional): // app.use(middleware({ jsonRegex: /\.(json|data)$/, extRegex: /\.(md|html|hbs)$/ }));
Debug
Known issues
gotchaThis library is specifically designed for the `base-methods` ecosystem (e.g., Assemble, Verb, Generate). It may not function as expected or integrate easily with other Node.js web frameworks (like Express or Koa) without significant adaptation or manual hook integration.
fix
Use `common-middleware` exclusively with applications built on `base-methods` or its derivatives like `assemble-core`.
affects: >=1.0.0
gotchaThe package is exclusively a CommonJS module. Attempting to use ESM `import` syntax will result in a `SyntaxError` in Node.js environments configured for CommonJS, or incorrect behavior in pure ESM projects unless handled by a build tool or wrapper.
fix
Always use `const middleware = require('common-middleware');` for consuming this package.
affects: >=1.0.0
breakingThe `common-middleware` package is in maintenance mode and has not been updated in over two years (last updated 2024 as of current date). While generally stable, compatibility with newer Node.js versions (e.g., Node.js 16, 18, 20+) or modern JavaScript features is not guaranteed, and runtime environment changes might introduce unforeseen issues without official patches.
fix
Thoroughly test `common-middleware` in your specific target Node.js environment. For critical applications, consider forking the repository for active maintenance or exploring more actively maintained alternatives if available within your ecosystem.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Attempting to use `import` syntax for `common-middleware` in a CommonJS-only Node.js environment or without proper transpilation.
fix
Change `import middleware from 'common-middleware';` to `const middleware = require('common-middleware');`.
TypeError: app.use is not a function
The `common-middleware` package expects to be registered with an application instance that provides an `app.use()` method, typically from the `base-methods` family (e.g., `assemble-core`). This error occurs if `app` is a plain object or an incompatible framework.
fix
Ensure that the `app` object you are calling `app.use()` on is an instance of `assemble-core` or a compatible `base-methods` application (e.g., `const app = assemble();`).
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
assemble-corerequiredFunctionally required for quickstart and typical usage, as `common-middleware` is designed to be registered with `assemble-core` or similar `base-methods` applications.
Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
common-middleware — npm install common-middleware · libregistry