Registry / web-framework / node-dependency-injection-express-middleware

node-dependency-injection-express-middleware

JSON →
library1.2.2jsnpmunverified

A dependency injection middleware for Express that integrates with the node-dependency-injection container. Version 1.2.2 provides a middleware class that parses a YAML service configuration file and injects the container into the request object. Supports compilation, compiler passes, custom loggers, and container registration as a service. Key differentiator is its simple Express integration approach via middleware rather than requiring complex framework integration. Release cadence is low; last release was v1.2.2.

npm install node-dependency-injection-express-middleware
INSTALL
IMPORT
SIG · NODE-DEPENDENCY-IN
N
node-dependency-injection-express-middleware
web-frameworkjavascriptv1.2.2
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.

NodeInjectionMiddleware
import NodeInjectionMiddleware from 'node-dependency-injection-express-middleware'
const NodeInjectionMiddleware = require('node-dependency-injection-express-middleware')
Default import. CommonJS require works but TypeScript may need esModuleInterop.
NodeInjectionMiddleware (named)
import { NodeInjectionMiddleware } from 'node-dependency-injection-express-middleware'
import NodeInjectionMiddleware from 'node-dependency-injection-express-middleware'
Named export also available. Default and named export are equivalent.
middleware() function
const middleware = new NodeInjectionMiddleware(options).middleware()
NodeInjectionMiddleware(options).middleware()
Must instantiate with 'new' before calling .middleware()

Shows minimal Express app using dependency injection middleware with YAML configuration.

import express from 'express'; import NodeInjectionMiddleware from 'node-dependency-injection-express-middleware'; const app = express(); const options = { serviceFilePath: 'services.yml', }; const middleware = new NodeInjectionMiddleware(options).middleware(); app.use(middleware); app.get('/service', (req, res) => { const container = req.container; const myService = container.get('my.service'); res.send(myService.doSomething()); }); app.listen(3000);
Debug
Known issues
gotchaThe middleware requires 'new' keyword when constructing NodeInjectionMiddleware; omitting it will throw an error.
fix
Always call `new NodeInjectionMiddleware(options).middleware()`.
affects: >=1.0.0
gotchaThe options.serviceFilePath must be a valid path to a YAML file. If the file is missing or invalid YAML, the middleware will throw at runtime.
fix
Ensure the YAML file exists and is correctly formatted.
affects: >=1.0.0
gotchaThe container is attached to req.container only after the middleware runs. Make sure your routes are defined after app.use() or use a router-level middleware.
fix
Call app.use(middleware) before defining routes that use req.container.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: NodeInjectionMiddleware is not a constructor
Forgetting 'new' keyword when instantiating the middleware class.
fix
Use `new NodeInjectionMiddleware(options)` instead of `NodeInjectionMiddleware(options)`.
Error: Cannot find module 'js-yaml'
Missing dependency js-yaml which is required to parse YAML service files.
fix
Run `npm install js-yaml` or ensure it is in your package.json.
TypeError: Cannot read properties of undefined (reading 'container')
Route handler tries to access req.container before the middleware has been applied.
fix
Ensure `app.use(middleware)` is placed before the route definitions.
Upgrade
Version history
1.2.2latest on npm
Audit
Dependencies
node-dependency-injectionrequiredcore container library used to manage services
js-yamlrequiredparsing YAML service configuration files
expressrequiredpeer dependency for the middleware to work with Express apps
Agent activity
2 hits · last 30 days
node
2
Resources
node-dependency-injection-express-middleware — npm install node-dependency-injection-express-middleware · libregistry