
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
container.js
Advanced tools

A dead-simple instance container for node.js.
Container.js aims to be as simple and unobtrusive as possible while providing a reliable way to store and access instances of a predefined constructor. While it can be used in many ways , the main motivation behind the module was to provide a way to share constructor instances between a node.js application by attaching a container instance to the class/constructor.
npm install container.js
On it's simplest form
var Container = require("container.js");
var constructorContainer = new Container(Constructor);
However a most likely desired usage will be the following
var Container = require("container.js");
var Constructor = function(){
};
Constructor.container = new Container(Constructor);
module.exports = Constructor;
for if the Human constructor module is exported and then required elsewhere, the container and it's items will be available as
var Constructor = require('constructor');
Constructor.container...
If you would like to define default arguments for all constructed instances which can be overridden/extended, it is possible to do so in two ways.
Let
var Human = function(gender,country,favouriteColor){
this.gender = gender;
this.country = country;
this.favouriteColor = favouriteColor;
};
module.exports = Human;
If your constructor accept one or multiple arguments as the previously defined Human constructor and not a single configuration object you can define your container default arguments as
// Instantiate the container with the Human constructor.
var container = new Container(Human);
// Set the default arguments
container.defaults = ['male','USA','yellow'];
And then whenever you add a new instance to your container as
container.add('paul');
The Human constructor will now be called with the 'male','USA','yellow' arguments .
Call the add method with the individual instance arguments as
container.add('sarah','female','canada','pink');
Call the add method with the individual instance arguments and undefined to use the default value for a parameter
container.add('carl',undefined,undefined,'green');
The Human constructor will now be called with the 'male','USA','green' arguments (we previously defined 'male','USA' as defaults)
Let
var Alien = function(configuration){
this.specie = configuration.specie;
this.planet = configuration.planet;
this.language = configuration.language;
};
module.exports = Alien;
If your constructor accepts single configuration object, you can define your container default arguments as
// Instantiate the container with the Alien constructor.
var container = new Container(Alien);
// Set the default arguments
container.defaults = {
specie : 'wookie',
planet : 'kashyyyk',
language : 'shyriiwook'
};
And then whenever you add a new instance to your container as
container.add('chewbacca');
The Alien constructor will now be called with the configuration object
{
specie : 'wookie',
planet : 'kashyyyk',
language : 'shyriiwook'
}
Call the add method with the individual instance configuration object attributes as
container.add('han solo',{
specie : 'human',
planet : 'corellia',
language : 'english'
});
Call the add method with the individual instance configuration argument attributes omitting the attributes where the default value should be used
container.add('wicket',{
specie : 'ewok'
});
The Alien constructor will now be called with the configuration object
(we previously defined the planet and language defaults)
{
specie : 'ewok',
planet : 'kashyyyk',
language : 'shyriiwook'
}
// Returns the added instance
container.add(identifier,args...);
// Returns the retrieved instance.
container.get(identifier);
container.remove(identifier);
// Returns a boolean.
container.has(identifier); // Returns a boolean
curl http://npmjs.org/install.sh | sh
[sudo] npm install container.js
All of the Container.js tests are written in jasmine, and designed to be run with npm.
$ npm install --dev
$ npm test
FAQs
A dead-simple instance container for node.js.
We found that container.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.