Need private packages and team management tools?Check out npm Teams »


2.0.0 • Public • Published


A semantic dependency injection framework

Build Status npm version

This repository contains the source code of Components.js. Full documentation on its usage can be found at


Components.js is a dependency injection framework for JavaScript applications.

Instead of hard-wiring software components together, Components.js allows these components to be instantiated and wired together declaratively using semantic configuration files. The advantage of these semantic configuration files is that software components can be uniquely and globally identified using URIs.

Configurations can be written in any RDF serialization, such as JSON-LD.

This software is aimed for developers who want to build modular and easily configurable and rewireable JavaScript applications.

Quick Start

Components.js can be installed using npm:

$ [sudo] npm install componentsjs

1. Define your module and its components


  "@context": [
    { "ex": "" }
  "@id": "ex:MyModule",
  "@type": "Module",
  "requireName": "my-module",
  "components": [
      "@id": "ex:MyModule/MyComponent",
      "@type": "Class",
      "requireElement": "MyComponent",
      "parameters": [
        { "@id": "ex:MyModule/MyComponent#name", "unique": true }
      "constructorArguments": [
        { "@id": "ex:MyModule/MyComponent#name" }

The npm module my-module exports a component with the name MyComponent.

The constructor of MyComponent takes a single name argument.

2. Create a configuration file containing a component instantiation


  "@context": [
      "ex": "",
      "name": "ex:MyModule/MyComponent#name"
  "@id": "",
  "@type": "ex:MyModule/MyComponent",
  "name": "John"

This configuration is a semantic representation of the instantiation of MyComponent with name set to "John".

3. Instantiate your component programmatically

const Loader = require('componentsjs').Loader;
const loader = new Loader();
await loader.registerModuleResourcesUrl('path/or/url/to/my-module.jsonld');
const myComponent = await loader.instantiateFromUrl(
    '', 'path/or/url/to/config-my-component.jsonld');

myComponent is an instance of type MyComponent, as defined in the config file.


Components.js is written by Ruben Taelman.

This code is copyrighted by Ghent University – imec and released under the MIT license.