---
url: /api/di/types/common/fn/function-constant.md
description: api documentation of constant from @tsed/di
---

## Usage

```typescript
import { constant } from "@tsed/di";
```

> See [/packages/di/src/common/fn/constant.ts](https://github.com/tsedio/tsed/blob/v8.40.1/packages/di/src/common/fn/constant.ts#L0-L0).

## Overview

```ts
function constant<Type>(expression: string): Type | undefined;
export function constant<Type>(expression: string, defaultValue: Type | undefined): Type;
```

* **expression** (`string`): Dot-notation path to the configuration value (e.g., "logger.level")

* **defaultValue** (\`\`): default value if the expression is not found

## Description

Get a constant value from the injector configuration settings.

Retrieves a configuration value using dot notation path syntax.
Useful for accessing environment variables, configuration constants, or settings.

### Usage

```typescript
import {constant} from "@tsed/di";

const apiKey = constant<string>("api.key");
const port = constant<number>("server.port", 3000);
const debug = constant<boolean>("logger.debug", false);
```
