# Getting Started

The `class-transformer` package is a zero-dependency utility library helping you to quickly transform class instances to plain objects and vice-versa. It works well with the [`class-validator`](https://github.com/typestack/class-validator/) library. The main features include:

* conditionally transforming object properties
* excluding specific properties from the transformed object
* exposing properties under a different name on the transformed object
* supports both NodeJS and browsers
* fully three-shakable
* zero external dependencies

## Installation

To start using class-transformer install the required packages via NPM:

```bash
npm install class-transformer reflect-metadata
```

Import the `reflect-metadata` package at the **first line** of your application:

```ts
import 'reflect-metadata';

// Your other imports and initialization code
// comes here after you imported the reflect-metadata package!
```

As the last step, you need to enable emitting decorator metadata in your Typescript config. Add these two lines to your `tsconfig.json` file under the `compilerOptions` key:

```json
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
```

Now you are ready to use class-transformer with Typescript!

## Basic Usage

The most basic usage is to transform a class to a plain object:

```ts
import { Expose, Exclude, classToPlain } from 'class-transformer';

class User {
  /**
   * When transformed to plain the `_id` property will be remapped to `id`
   * in the plain object.
   */
  @Expose({ name: 'id' })
  private _id: string;

  /**
   * Expose the `name` property as it is in the plain object.
   */
  @Expose()
  public name: string;

  /**
   * Exclude the `passwordHash` so it won't be included in the plain object.
   */
  @Exclude()
  public passwordHash: string;
}

const user = getUserMagically();
// contains: User { _id: '42', name: 'John Snow', passwordHash: '2f55ce082...' }

const plain = classToPlain(user);
// contains { id: '42', name: 'John Snow' }
```


---

# Agent Instructions: 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:

```
GET https://docs.typestack.community/class-transformer/01-getting-started.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
