Registry / web-framework / polkadot-middleware

polkadot-middleware

JSON →
library1.0.1jsnpmunverified

The `polkadot-middleware` package provides a familiar middleware pattern for the `polkadot` HTTP server, streamlining request handler composition. Currently at version 1.0.1, it offers a functional alternative to manual function nesting, simplifying the development of server-side logic. This library addresses the current lack of a native pipeline operator in JavaScript, allowing developers to chain asynchronous request/response functions linearly. It serves a specific niche for users of the lightweight `polkadot` server who desire an Express.js-like middleware experience without significant overhead, focusing on readability and maintainability for simple API servers.

npm install polkadot-middleware
INSTALL
IMPORT
SIG · POLKADOT-MIDDLEWAR
P
polkadot-middleware
web-frameworkjavascriptv1.0.1
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
import middleware from 'polkadot-middleware'
const { middleware } = require('polkadot-middleware')
The library primarily uses a default export pattern for both CJS and ESM.
polkadot
import polkadot from 'polkadot'
const { polkadot } = require('polkadot')
`polkadot` itself is typically imported as a default export.

Demonstrates chaining multiple middleware functions for error handling and cache control with a basic response using `polkadot-middleware`.

import polkadot from 'polkadot'; import middleware from 'polkadot-middleware'; async function handleErrors(next) { return async (req, res) => { try { return await next(req, res); } catch (err) { res.statusCode = 500; return err.message || err; } }; } async function setCacheControl(next) { return async (req, res) => { res.setHeader(`Cache-Control`, `public, max-age=` + 3600); return next(req, res); }; } middleware( polkadot, handleErrors, setCacheControl, (req, res) => 'Sup dawg' ).listen(8080, () => console.log('Server listening on http://localhost:8080'));
Debug
Known issues
gotchaThe primary utility of `polkadot-middleware` is as a temporary solution until the TC39 pipeline operator proposal is fully adopted and implemented in JavaScript runtimes. Once standardized, native language features may offer a more direct and potentially performant way to achieve similar composition.
fix
No immediate fix required, but be aware of future language changes that might make this library less critical.
affects: >=1.0.0
gotchaThis library is specifically designed for the `polkadot` HTTP server. It is not a general-purpose middleware solution and cannot be directly applied to other Node.js HTTP frameworks like Express.js, Koa, or Fastify.
fix
Ensure you are using `polkadot` as your HTTP server. For other frameworks, use their native middleware solutions.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: polkadot is not a function
The `polkadot` package was not installed or incorrectly imported, or an older version of `polkadot` with a different API is being used.
fix
Run `npm install polkadot` or `yarn add polkadot`. Verify your `polkadot` import statement matches its export type (e.g., `import polkadot from 'polkadot'` for ESM).
ReferenceError: middleware is not defined
The `polkadot-middleware` package was not installed, incorrectly imported, or the import path is wrong.
fix
Run `npm install polkadot-middleware` or `yarn add polkadot-middleware`. Ensure the import statement is correct, typically `import middleware from 'polkadot-middleware'` or `const middleware = require('polkadot-middleware')`.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
polkadotrequiredThis package is a middleware wrapper specifically designed for the `polkadot` HTTP server and cannot function independently.
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
polkadot-middleware — npm install polkadot-middleware · libregistry