Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including another-di with all npm packages installed. Try it out:

var anotherDi = require("another-di")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

another-di v3.0.0

Yeah it's a di for javascript...


This is another dependency injector, because there aren't enough.


// lib/hello-message.js

module.exports = function () {
  return 'hello world!';

// lib/boomer.js

module.exports = function ({helloMessage}) {
  return {
    boom: function () {

// lib/index.js

var di = require('another-di');

module.exports = di.create()
.singleton('helloMessage', require('./hello-message')) // dashes converted to camelcase
.singleton('boomer', require('./boomer'))

// main.js

var lib = require('./lib'); ({boomer}) {
  boomer.boom(); // logs out 'hello world'

// test.js

var lib = require('./lib');
var boomer;

beforeEach(function () {
  testContainer = lib.clone();
  testContainer.singleton('helloMessage', function () {
    return 'hello from test land';
  }); ({_boomer}) { // underscore is striped before dependency lookup
    boomer = _boomer;

it('should boom!', () => {
  boomer.boom(); // logs 'hello from test land'


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free