# gt-node: General Translation Node.js SDK: Quickstart URL: https://generaltranslation.com/en-GB/docs/node/quickstart.mdx --- title: Quickstart description: Install the General Translation gt-node library and translate your first Node.js service. related: links: - /docs/node/guides/translating-strings - /docs/node/guides/detecting-locale - /docs/node/guides/configuring - /docs/node/guides/storing-translations --- `gt-node` translates strings in Node.js servers and services. You initialise it once, bind the locale for each incoming request, and translate strings in your handlers. Use `gt-node` for backend services such as Express or Fastify APIs. For React apps, use [`gt-react`](/docs/react/react-quickstart); for Next.js, use [`gt-next`](/docs/react/nextjs-quickstart). *Note: `gt-node` requires Node.js 18 or later. Per-request locale binding uses `AsyncLocalStorage` from `node:async_hooks`.* ## What gt-node does [#what-it-does] `gt-node` gives you: * **String translation** with [`getGT`](/docs/node/reference/functions/get-gt), for handler-local strings. * **Registered messages** with [`msg`](/docs/node/reference/functions/msg) and [`getMessages`](/docs/node/reference/functions/get-messages), for shared constants and errors. * **Runtime translation** with [`tx`](/docs/node/reference/functions/tx), for dynamic content. * **Per-request locale** binding with [`withGT`](/docs/node/reference/functions/with-gt), plus helpers to detect the request locale. ## Quickstart [#quickstart] Install the library, initialise it, bind a locale to each request, and translate a string. ### 1. Install `gt-node` Install `gt-node` as a dependency and the [`gt` CLI](/docs/cli/quickstart) as a dev dependency. ```bash npm install gt-node && npm install gt --save-dev ``` ```bash yarn add gt-node && yarn add --dev gt ``` ```bash bun add gt-node && bun add --dev gt ``` ```bash pnpm add gt-node && pnpm add --save-dev gt ``` ### 2. Initialise the library Call [`initializeGT`](/docs/node/reference/functions/initialize-gt) once on start-up, before handling requests. Pass your locales and credentials — `gt-node` does not automatically read `gt.config.json` or environment variables. ```ts title="server.js" import { initializeGT } from 'gt-node'; initializeGT({ defaultLocale: 'en', locales: ['en', 'es', 'fr'], projectId: process.env.GT_PROJECT_ID, }); ``` ### 3. Bind the request locale Wrap each request in `withGT` so translation functions know the target locale. Use [`getRequestLocale`](/docs/node/reference/functions/get-request-locale) to detect it from the `Accept-Language` header. ```ts title="server.js" import express from 'express'; import { withGT, getRequestLocale } from 'gt-node'; const app = express(); app.use((req, res, next) => withGT(getRequestLocale(req), () => next())); ``` ### 4. Translate a string Inside a handler, await `getGT` to get a translation function for the request's locale, then translate strings. Interpolate values with ICU placeholders. ```ts title="server.js" import { getGT } from 'gt-node'; app.get('/api/greeting', async (req, res) => { const gt = await getGT(); res.json({ message: gt('Hello, {name}!', { name: 'Alice' }) }); }); ``` ### 5. Generate translations Run the CLI before you deploy to production so translations are available at runtime. ```bash npx gt translate ``` See [Translating strings](/docs/node/guides/translating-strings) for when to use `getGT`, `msg`, and `tx`, and [Configuring gt-node](/docs/node/guides/configuring) for credentials and delivery. ## Next steps - /docs/node/guides/translating-strings - /docs/node/guides/detecting-locale - /docs/node/guides/configuring - /docs/node/guides/storing-translations