# gt-node: General Translation Node.js SDK: initializeGT
URL: https://generaltranslation.com/en-US/docs/node/reference/functions/initialize-gt.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: Configure the General Translation gt-node library once at server startup. API reference for initializeGT.

Configures General Translation for use in a Node.js runtime. Call `initializeGT` once, before any other translation function, to set up locales, credentials, and translation delivery.

## Overview [#overview]

Call `initializeGT` at the top of your server's entry file. It reads credential fallbacks from `GT_PROJECT_ID`, `GT_API_KEY`, and `GT_DEV_API_KEY`, but it does not read `gt.config.json` automatically. See the [configuration reference](/docs/node/reference/config) for the full option list.

```ts
import { initializeGT } from 'gt-node';

initializeGT({
  defaultLocale: 'en',
  locales: ['en', 'es', 'fr'],
});
```

Signature:

```ts
initializeGT(config: InitializeGTParams): void
```

*Note: `initializeGT` must be called before using [`withGT`](/docs/node/reference/functions/with-gt), [`getGT`](/docs/node/reference/functions/get-gt), [`getMessages`](/docs/node/reference/functions/get-messages), or any other translation function. Calling those functions first throws an error.*

## How it works [#how-it-works]

- **One-time setup.** Call `initializeGT` exactly once during server initialization. It sets up locale configuration, the translation cache, and per-request locale storage.
- **Credential precedence.** Explicit nonempty `projectId`, `apiKey`, and `devApiKey` values take precedence. Omitted or empty values fall back to their matching environment variables.
- **Delivery mode.** Provide `projectId` to load translations from the General Translation CDN, or [`loadTranslations`](/docs/react/reference/functions/load-translations) to bring your own source. For on-demand translation in development, also provide `devApiKey`.
- **Synchronous.** The call returns immediately and does not await network requests.

## Parameters [#parameters]

| Parameter | Description | Type | Optional | Default |
| --- | --- | --- | --- | --- |
| [`config`](#config) | Configuration object. See the [configuration reference](/docs/node/reference/config). | `InitializeGTParams` | No | — |

### `config` [#config]

**Type** `InitializeGTParams` · **Required**

An object combining locale, credential, cache, and dictionary options. The object is required, but every field on it is optional. Every field is documented in the [configuration reference](/docs/node/reference/config). Commonly used fields:

- `defaultLocale` — source and fallback locale (default `'en'`).
- `locales` — supported target locales.
- `projectId` — project ID; enables the CDN loader when set.
- `apiKey` — production API key.
- `devApiKey` — development API key for on-demand translation.
- `loadTranslations` — custom loader returning translations for a locale.
- `customMapping` — locale aliases and property overrides.

## Returns [#returns]

**Type** `void`

## Examples [#examples]

```ts title="server.js"
// Basic setup
import { initializeGT } from 'gt-node';

initializeGT({
  defaultLocale: 'en',
  locales: ['en', 'es', 'fr', 'ja'],
  // Credentials are read from GT_PROJECT_ID, GT_API_KEY, and GT_DEV_API_KEY.
});
```

```ts title="server.js"
// With a custom translation loader
import { initializeGT } from 'gt-node';

initializeGT({
  defaultLocale: 'en',
  locales: ['en', 'es'],
  loadTranslations: async (locale) => {
    const res = await fetch(`https://my-api.com/translations/${locale}`);
    return res.json();
  },
});
```

## Version history [#version-history]

| Version | Changes |
| --- | --- |
| `gt-node` 1.0.8 | Added `GT_PROJECT_ID`, `GT_API_KEY`, and `GT_DEV_API_KEY` environment fallbacks. Explicit nonempty parameters still take precedence. |

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
