Registry /
web-framework / node-dependency-injection-express-middleware
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
muslnode 18–226 runs
build_error
glibcnode 18–226 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);
Errors
Common errors & fixes
TypeError: NodeInjectionMiddleware is not a constructor
Forgetting 'new' keyword when instantiating the middleware class.
fixUse `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.
fixRun `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.
fixEnsure `app.use(middleware)` is placed before the route definitions.
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