> For the complete documentation index, see [llms.txt](https://docs.typestack.community/typedi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.typestack.community/typedi/develop/usage-without-typescript/01-getting-started.md).

# Getting Started

It's possible to use TypeDI without TypesScript, however some of the functionality is limited or not available. These differences are listed below in the [Limitations](#limitations) section.

## Installation

To start using TypeDI with JavaScript install the required packages via NPM:

```bash
npm install typedi reflect-metadata
```

## Basic usage

The most basic usage is to request an instance of a class definition. TypeDI will check if an instance of the class has been created before and return the cached version or it will create a new instance, cache and return it.

```js
import 'reflect-metadata';
import { Container } from 'typedi';

class ExampleClass {
  print() {
    console.log('I am alive!');
  }
}

/** Register this class to the TypeDI container */
Container.set({ id: ExampleClass, type: ExampleClass });

/** Request an instance of ExampleClass from TypeDI. */
const classInstance = Container.get(ExampleClass);

/** We received an instance of ExampleClass and ready to work with it. */
classInstance.print();
```

For more advanced usage examples and patterns please read the [next page](/typedi/develop/usage-without-typescript/usage/02-basic-usage.md).

## Limitations

When registering your dependencies with the `Container.set()` method, there are three options available that must be set. Either one of the following are allowed: `type`, `factory`, or `value` but not more than one.

* `Container.set({ id: ExampleClass, type: ExampleClass});`
* `Container.set({ id: ExampleClass, value: new ExampleClass});`
* `Container.set({ id: ExampleClass, factory: ExampleClass});`

To get started quickly, it is recommend to use `type` due to the fact that using `value` will instantiate the class before it's registered to the TypeDI Container. Using `type` will also assure that the TypeDI Container is injected to the constructor.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.typestack.community/typedi/develop/usage-without-typescript/01-getting-started.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
