@kopynator/node
v1.0.2
Published
Node.js wrapper for Kopynator
Readme
@kopynator/node
Node.js wrapper for the Kopynator i18n platform. Includes Express middleware support.
Features
- Express Middleware: Auto-detects locale from headers or query params.
- Server-Side: Fetch translations for CLI tools, CRON jobs, or APIs.
- TypeScript: Full type safety for your configuration and translations.
Installation
npm install @kopynator/core @kopynator/nodeUsage
1. With Express
The middleware automatically attaches the t function to the request object.
import { createKopyNode } from '@kopynator/node';
import express from 'express';
const app = express();
const kopyNode = createKopyNode({
apiKey: 'YOUR_API_KEY',
defaultLocale: 'en',
mode: 'live'
});
// Load initial translations
await kopyNode.init();
app.use(kopyNode.middleware());
app.get('/', (req, res) => {
// Use the auto-detected locale helper
const title = req.t('welcome_message');
res.send(`<h1>${title}</h1>`);
});Locale Detection Logic
The middleware checks for locale in the following order:
- Query Parameter:
?lang=es - Header:
Accept-Language(extracts the first language) - Default: Falls back to
defaultLocalefrom config.
2. General Node.js Usage
For scripts or other frameworks:
import { createKopyNode } from '@kopynator/node';
const kopy = createKopyNode({ apiKey: '...', defaultLocale: 'en' });
await kopy.init();
console.log(kopy.t('greeting'));Configuration Options
| Option | Type | Description |
|---|---|---|
| apiKey | string | Required. Your public project token. |
| defaultLocale | string | Required. The fallback language. |
| mode | 'local' \| 'live' | Determines how translations are loaded. |
