deepl-node is the official DeepL Node.js client library
npm install deepl-node


Official Node.js Client Library for the DeepL API.
The [DeepL API][api-docs] is a language translation API that allows other
computer programs to send texts and documents to DeepL's servers and receive
high-quality translations. This opens a whole universe of opportunities for
developers: any translation product you can imagine can now be built on top of
DeepL's best-in-class translation technology.
The DeepL Node.js library offers a convenient way for applications written for
Node.js to interact with the DeepL API. We intend to support all API functions
with the library, though support for new features may be added to the library
after they're added to the API.
To use the package, you'll need an API authentication key. To get a key,
[please create an account here][create-account]. With a DeepL API Free account
you can translate up to 500,000 characters/month for free.
npm install deepl-node
The package officially supports Node.js version 12, 14, 16, 17, 18, 20, 22 and 24.
We strongly recommend upgrading to a supported Node.js version as we will be dropping support for end-of-life versions in 2025. You can find the Node versions and support timelines [here][node-version-list].
Import the package and construct a DeepLClient. The first argument is a string
containing your API authentication key as found in your
[DeepL Pro Account][pro-account].
Be careful not to expose your key, for example when sharing source code.
An example using async/await and ES Modules:
``javascript
import * as deepl from 'deepl-node';
const authKey = "f63c02c5-f056-..."; // Replace with your key
const deeplClient = new deepl.DeepLClient(authKey);
(async () => {
const result = await deeplClient.translateText('Hello, world!', null, 'fr');
console.log(result.text); // Bonjour, le monde !
})();
`
This example is for demonstration purposes only. In production code, the
authentication key should not be hard-coded, but instead fetched from a
configuration file or environment variable.
If you are using CommonJS, you should instead require the package:
`javascript`
const deepl = require('deepl-node');
const deeplClient = new deepl.DeepLClient(authKey);
DeepLClient accepts options as the second argument, see
Configuration for more information.
All DeepLClient functions return promises, and for brevity the examples in thisawait
file use and try/catch blocks, however Promise-chaining is also
possible:
`javascript`
deeplClient
.translateText('Hello, world!', null, 'fr')
.then((result) => {
console.log(result.text); // Bonjour, le monde !
})
.catch((error) => {
console.error(error);
});
The package also supports TypeScript:
`typescript
import * as deepl from 'deepl-node';
(async () => {
const targetLang: deepl.TargetLanguageCode = 'fr';
const results = await deeplClient.translateText(
['Hello, world!', 'How are you?'],
null,
targetLang,
);
results.map((result: deepl.TextResult) => {
console.log(result.text); // Bonjour, le monde !
});
})();
`
To translate text, call translateText(). The first argument is a string
containing the text you want to translate, or an array of strings if you want to
translate multiple texts.
The second and third arguments are the source and target language codes.
Language codes are case-insensitive strings according to ISO 639-1, for
example 'de', 'fr', 'ja''. Some target languages also include the regional'en-US'
variant according to ISO 3166-1, for example , or 'pt-BR'. The sourcenull
language also accepts , to enable auto-detection of the source language.
The last argument to translateText() is optional, and specifies extra
translation options, see Text translation options
below.
translateText() returns a Promise that fulfills with a TextResult, or anTextResult
array of s corresponding to your input text(s). TextResult has thetext
following properties:
- is the translated text,detectedSourceLang
- is the detected source language code,billedCharacters
- is the number of characters billed for the text.modelTypeUsed
- indicates the translation model used, but is undefinedmodelType
unless the option is specified.
`javascript
// Translate text into a target language, in this case, French:
const translationResult = await deeplClient.translateText('Hello, world!', 'en', 'fr');
console.log(translationResult.text); // 'Bonjour, le monde !'
// Translate multiple texts into British English:
const translations = await deeplClient.translateText(
['お元気ですか?', '¿Cómo estás?'],
null,
'en-GB',
);
console.log(translations[0].text); // 'How are you?'
console.log(translations[0].detectedSourceLang); // 'ja'
console.log(translations[0].billedCharacters); // 7 - the number of characters in the source text "お元気ですか?"
console.log(translations[1].text); // 'How are you?'
console.log(translations[1].detectedSourceLang); // 'es'
console.log(translations[1].billedCharacters); // 12 - the number of characters in the source text "¿Cómo estás?"
// Translate into German with less and more Formality:
console.log(await deeplClient.translateText('How are you?', null, 'de', { formality: 'less' })); // 'Wie geht es dir?'
console.log(await deeplClient.translateText('How are you?', null, 'de', { formality: 'more' })); // 'Wie geht es Ihnen?'
`
#### Text translation options
- splitSentences: specify how input text should be split into sentences,'on'
default: .'on'
- : input text will be split into sentences using both newlines and'off'
punctuation.
- : input text will not be split into sentences. Use this for'nonewlines'
applications where each input text contains only one sentence.
- : input text will be split into sentences using punctuationpreserveFormatting
but not newlines.
- : controls automatic-formatting-correction. Set to truefalse
to prevent automatic-correction of formatting, default: .formality
- : controls whether translations should lean toward informal orprefer_*
formal language. This option is only available for some target languages, see
Listing available languages. Use the
options to apply formality if it is available for the target 'less'
language, or otherwise fallback to the default.
- : use informal language.'more'
- : use formal, more polite language.'default'
- : use default formality.'prefer_less'
- : use informal language if available, otherwise default.'prefer_more'
- : use formal, more polite language if available, otherwise default.glossary
- : specifies a glossary to use with translation, either as a stringMultilingualGlossaryInfo
containing the glossary ID, or a /GlossaryInfo as returned bygetMultilingualGlossary()
/getGlossary().styleRule
- : specifies a style rule to use with translation, either as a stringStyleRuleInfo
containing the style rule ID, or a as returned by getAllStyleRules().context
- : specifies additional context to influence translations, that is notcontext
translated itself. Characters in the parameter are not counted toward billing.customInstructions
See the [API documentation][api-docs-context-param] for more information and
example usage.
- : an array of instructions to customize the translation behavior.de
Up to 10 custom instructions can be specified, each with a maximum of 300 characters.
Important: The target language must be , en, es, fr, it, ja, ko, zhcustomInstructions
or any variants of these languages.
Note: Any request with the parameter enabled will use quality_optimized
the model type as the default. Requests combining customInstructions
and modelType: latency_optimized will be rejected.modelType
- : specifies the type of translation model to use, options are:'quality_optimized'
- : use a translation model that maximizes translation'prefer_quality_optimized'
quality, at the cost of response time. This option may be unavailable for
some language pairs.
- : use the highest-quality translation model 'latency_optimized'
for the given language pair.
- : use a translation model that minimizes responsetagHandling
time, at the cost of translation quality.
- : type of tags to parse before translation, options are 'html''xml'
and .tagHandlingVersion
- : specifies which version of the tag handling algorithm to use.v1
Options are and v2.
The following options are only used if tagHandling is 'xml':
- outlineDetection: specify false to disable automatic tag detection,true
default is .splittingTags
- : list of XML tags that should be used to split text into['tag1', 'tag2']
sentences. Tags may be specified as an array of strings (),'tag1,tag2'
or a comma-separated list of strings (). The default is an emptynonSplittingTags
list.
- : list of XML tags that should not be used to split textsplittingTags
into sentences. Format and default are the same as for .ignoreTags
- : list of XML tags that containing content that should not besplittingTags
translated. Format and default are the same as for .extraRequestParameters
- : Extra body parameters to be passed along with the{'param': 'value', 'param2': 'value2'}
HTTP request. Only string values are permitted.
For example: target_lang
Note: Extra request parameters can override parameters explicitly set by the library
(such as , source_lang, etc.). This is primarily useful for testing or
accessing beta features.
To translate documents, call translateDocument(). The first and secondfilename
arguments are the input and output files. These arguments accept strings
containing file paths, or Streams or FileHandles opened for reading/writing. The
input file may also be given as a Buffer containing the file data. Note that if
the input file is not given as a file path, then the option is
required.
The third and fourth arguments are the source and target language codes, and
they work exactly the same as when translating text with translateText().
The last argument to translateDocument() is optional, and specifies extra
translation options, see
Document translation options below.
`javascriptDocument ID: ${handle.documentId},
// Translate a formal document from English to German:
try {
await deeplClient.translateDocument(
'Instruction Manual.docx',
'Bedienungsanleitung.docx',
'en',
'de',
{ formality: 'more' },
);
} catch (error) {
// If the error occurs after the document was already uploaded,
// documentHandle will contain the document ID and key
if (error.documentHandle) {
const handle = error.documentHandle;
console.log( + Document key: ${handle.documentKey});Error occurred during document upload: ${error}
} else {
console.log();`
}
}
translateDocument() wraps multiple API calls: uploading, polling status until
the translation is complete, and downloading. If your application needs to
execute these steps individually, you can instead use the following functions
directly:
- uploadDocument(),getDocumentStatus()
- (or isDocumentTranslationComplete()), anddownloadDocument()
-
#### Document translation options
- formality: same as in Text translation options.glossary
- : same as in Text translation options.styleRule
- : same as in Text translation options.filename
- : if the input file is not provided as file path, this option isextraRequestParameters
needed to specify the file extension.
- : same as in Text translation options.enableDocumentMinification
- : A bool value. If set to true, the library will try to minify a document pptx
before translating it through the API, sending a smaller document if the file contains a lot of media. This is
currently only supported for and docx files. See also Document minification.
#### Document minification
In some contexts, one can end up with large document files (e.g. PowerPoint presentations
or Word files with many contributors, especially in a larger organization). However, the
DeepL API enforces a limit of 30 MB for most of these files (see Usage Limits in the docs).
In the case that most of this size comes from media included in the documents (e.g. images,
videos, animations), document minification can help.
In this case, the library will create a temporary directory to extract the document into,
replace the large media with tiny placeholders, create a minified document, translate that
via the API, and re-insert the original media into the original file. Please note that this
requires a bit of additional (temporary) disk space, we recommend at least 2x the file size
of the document to be translated.
To use document minification, simply pass the option to the translateDocument() function:`typescript`
await deeplClient.translateDocument(
inFile, outFile, "en", "de", { enableDocumentMinification: true }
);uploadDocument()
In order to use document minification with the lower-level ,isDocumentTranslationComplete() and downloadDocument() methods as well as other details,DocumentMinifier
see the class.
Currently supported document types for minification:
1. pptxdocx
2.
Currently supported media types for minification:
1. pngjpg
2. jpeg
3. emf
4. bmp
5. tiff
6. wdp
7. svg
8. gif
9. mp4
10. asf
11. avi
12. m4v
13. mpg
14. mpeg
15. wmv
16. mov
17. aiff
18. au
19. mid
20. midi
21. mp3
22. m4a
23. wav
24. wma
25.
Glossaries allow you to customize your translations using defined terms.
Multiple glossaries can be stored with your account, each with a user-specified
name and a uniquely-assigned ID.
#### v2 versus v3 glossary APIs
The newest version of the glossary APIs are the /v3 endpoints, allowing bothv2
editing functionality plus support for multilingual glossaries. New methods and
objects have been created to support interacting with these new glossaries.
Due to this new functionality, users are recommended to utilize these
multilingual glossary methods. However, to continue using the glossary API translator.ts
endpoints, please continue to use the existing endpoints in the createGlossary()
(e.g. , getGlossary(), etc).
To migrate to use the new multilingual glossary methods from the current
monolingual glossary methods, please refer to
this migration guide.
The following sections describe how to interact with multilingual glossaries
using the new functionality:
You can create a multi-lingual glossary with your desired terms and name using
createMultilingualGlossary(). Glossaries created via the /v3 endpoints can now
support multiple source-target language pairs. Note: Glossaries are only
supported for some language pairs, check the
[DeepL API documentation][api-docs] for more information.
`javascript`
// Create a glossary with an English to German dictionary containing two terms:
const entries = new deepl.GlossaryEntries({ entries: { artist: 'Maler', prize: 'Gewinn' } });
const glossaryEnToDe = await deeplClient.createMultilingualGlossary('My glossary', [{sourceLangCode: 'en', targetLangCode: 'de', entries: entries}]);
You can also upload a glossary downloaded from the DeepL website using
createGlossaryWithCsv(). Instead of supplying the entries as a dictionary,
provide the CSV content as a string.
`javascriptError reading file at ${filePath}:
const fs = require('fs').promises;
const filePath = '/path/to/glossary_file.csv';
let csvContent = '';
try {
csvContent = await fs.readFile(filePath, 'utf-8');
} catch (error) {
console.error(, error);`
throw error;
}
const csvContent = await readCsvFile(filePath);
const glossaryEnToDe = await deeplClient.createMultilingualGlossaryWithCsv('My glossary', 'en', 'de', csvContent);
The [API documentation][api-docs-csv-format] explains the expected CSV format in
detail.
Functions to get, list, and delete stored glossaries are also provided.
`javascriptGlossary ID: ${glossary.glossaryId}
// Find details about the glossary named 'My glossary'
const glossaries = await deeplClient.listMultilingualGlossaries();
const glossary = glossaries.find((glossary) => glossary.name == 'My glossary');
console.log();Contains dictionary, source: ${glossaryDict.sourceLang}, target: ${glossaryDict.targetLang}, with ${glossaryDict.entryCount} entries.
for (const glossaryDict of glossary.dictionaries) {
console.log(;)`
}
To use a glossary when translating text and documents, include the ID
(or MultilingualGlossaryInfo object returned by listMultilingualGlossaries() or createMultilingualGlossary()) in
the function call. The source and target languages must match the glossary.
`javascript`
const resultWithGlossary = await deeplClient.translateText(
'The artist was awarded a prize.',
'en',
'de',
{ glossary },
);
console.log(resultWithGlossary.text); // 'Der Maler wurde mit einem Gewinn ausgezeichnet.'
// Without using a glossary would give: 'Der Künstler wurde mit einem Preis ausgezeichnet.'
#### Getting, listing, and deleting stored glossaries
Functions to get, list, and delete stored glossaries are also provided:
- getMultilingualGlossary() takes a glossary ID and returns a Promise
object for a stored glossary, or raises anlistMultilingualGlossaries()
exception if no such glossary is found.
- returns a promise of a list of MultilingualGlossaryInfo objectsdeleteMultilingualGlossary()
corresponding to all of your stored glossaries.
- takes a glossary ID or MultilingualGlossaryInfo deleteMultilingualGlossaryDictionary()
object and deletes the stored glossary from the server, or raises an
exception if no such glossary is found.
- takes a glossary ID or GlossaryInfo object to MultilingualGlossaryDictionaryInfo
identify the glossary. Additionally takes in a source and target language or a
object and deletes the stored dictionary
from the server, or raises an exception if no such glossary dictionary is found.
`javascript
const glossaryDicts = [{sourceLangCode: 'en', targetLangCode: 'de', entries: new deepl.GlossaryEntries({ entries: {'hello': 'hallo'}})}, {sourceLangCode: 'de', targetLangCode: 'en', entries: new deepl.GlossaryEntries({ entries: {'hallo': 'hello'}})}];
const createdGlossary = await deeplClient.createMultilingualGlossary('My Glossary', glossaryDicts);
const glossaries = await deeplClient.listMultilingualGlossaries();
// Delete a dictionary in a glossary
await deeplClient.deleteMultilingualGlossaryDictionary(createdGlossary, 'de', 'en');
// Delete a glossary by name
for (const glossary of glossaries) {
if (glossary.name === "Old glossary") {
await deeplClient.deleteMultilingualGlossary(glossary);
}
}
`
#### Listing entries in a stored glossary
The MultilingualGlossaryInfo object does not contain the glossary entries, butentryCount
instead only the number of entries in the property.
To list the entries contained within a stored glossary, use
getMultilingualGlossaryEntries() providing either the MultilingualGlossaryInfo object or glossary
ID and the source and target language pair:
`javascript`
const entriesObj = await deeplClient.getMultilingualGlossaryDictionaryEntries(createdGlossary, 'en', 'de');
console.log(entriesObj.entries.toTsv()); // 'hello\thallo'
#### Editing a glossary
Functions to edit stored glossaries are also provided:
- updateMultilingualGlossaryDictionary() takes a glossary ID or MultilingualGlossaryInforeplaceMultilingualGlossaryDictionary()
object, plus a source language, target language, and a dictionary of entries.
It will then either update the list of entries for that dictionary (either
inserting new entries or replacing the target phrase for any existing
entries) or will insert a new glossary dictionary if that language pair is
not currently in the stored glossary.
- takes a glossary ID or MultilingualGlossaryInfoupdateMultilingualGlossaryName()
object, plus a source language, target language, and a dictionary of entries.
It will then either set the entries to the parameter value, completely
replacing any pre-existing entries for that language pair.
- takes a glossary ID or MultilingualGlossaryInfo
object, plus the new name of the glossary.
`javascript
const glossaryDicts = [{sourceLangCode: 'en', targetLangCode: 'de', entries: new deepl.GlossaryEntries({ entries: {"artist": "Maler", "hello": "guten tag"} })}];
const myGlossary = await deeplClient.createMultilingualGlossary('My Glossary', glossaryDicts);
const newDict = {sourceLangCode: 'en', targetLangCode: 'de', entries: new deepl.GlossaryEntries({ entries: {"hello": "hallo", "prize": "Gewinn"} })};
const updatedGlossary = await deeplClient.updateMultilingualGlossaryDictionary(myGlossary, newDict);
const entriesObj = await deeplClient.getMultilingualGlossaryDictionaryEntries(createdGlossary, 'en', 'de');
console.log(entriesObj.entries.toTsv()); // {'artist': 'Maler', 'hello': 'hallo', 'prize': 'Gewinn'}
`
For examples for the other methods please see this migration guide
Style rules allow you to customize your translations using a managed, shared list
of rules for style, formatting, and more. Multiple style rules can be stored with
your account, each with a user-specified name and a uniquely-assigned ID.
#### Creating and managing style rules
Currently style rules must be created and managed in the DeepL UI via
https://www.deepl.com/en/custom-rules. Full CRUD functionality via the APIs will
come shortly.
#### Listing all style rules
getAllStyleRules() returns a list of StyleRuleInfo objectspage
corresponding to all of your stored style rules. The method accepts optional
parameters: (page number for pagination, 0-indexed), pageSize (numberdetailed
of items per page), and (whether to include detailed configurationconfiguredRules
rules in the property).
`javascript${rule.name} (${rule.styleId})
// Get all style rules
const styleRules = await deeplClient.getAllStyleRules();
for (const rule of styleRules) {
console.log();
}
// Get style rules with detailed configuration
const styleRules = await deeplClient.getAllStyleRules({ detailed: true });
for (const rule of styleRules) {
if (rule.configuredRules) {
console.log( Number formatting: ${rule.configuredRules.numbers});`
}
}
To check account usage, use the getUsage() function.
The returned Usage object contains up to three usage subtypes, depending oncharacter
your account type: , document and teamDocument. For API accountscharacter will be defined, the others undefined.
Each usage subtypes (if defined) have count and limit properties giving thelimitReached()
amount used and maximum amount respectively, and the functionUsage
that checks if the usage has reached the limit. The top level object hasanyLimitReached()
the function to check all usage subtypes.
`javascriptCharacters: ${usage.character.count} of ${usage.character.limit}
const usage = await deeplClient.getUsage();
if (usage.anyLimitReached()) {
console.log('Translation limit exceeded.');
}
if (usage.character) {
console.log();Documents: ${usage.document.count} of ${usage.document.limit}
}
if (usage.document) {
console.log();`
}
You can request the list of languages supported by DeepL Translator for text and
documents using the getSourceLanguages() and getTargetLanguages() functions.Language
They both return an array of objects.
The name property gives the name of the language in English, and the codesupportsFormality
property gives the language code. The property only appearsBoolean
for target languages, and is a indicating whether the target languageformality
supports the optional parameter.
`javascript${lang.name} (${lang.code})
const sourceLanguages = await deeplClient.getSourceLanguages();
for (let i = 0; i < sourceLanguages.length; i++) {
const lang = sourceLanguages[i];
console.log(); // Example: 'English (en)'
}
const targetLanguages = await deeplClient.getTargetLanguages();
for (let i = 0; i < targetLanguages.length; i++) {
const lang = targetLanguages[i];
if (lang.supportsFormality) {
console.log(${lang.name} (${lang.code}) supports formality);`
// Example: 'German (DE) supports formality'
}
}
Glossaries are supported for a subset of language pairs. To retrieve those
languages use the getGlossaryLanguagePairs() function, which returns an arrayGlossaryLanguagePair
of objects. Each has sourceLang and targetLang
properties indicating that that pair of language codes is supported for
glossaries.
`javascript${languagePair.sourceLang} to ${languagePair.targetLang}
const glossaryLanguages = await deeplClient.getGlossaryLanguagePairs();
for (let i = 0; i < glossaryLanguages.length; i++) {
const languagePair = glossaryLanguages[i];
console.log();`
// Example: 'en to de', 'de to en', etc.
}
If you use this library in an application, please identify the application with
the appInfo field in the DeepLClientOptions, which takes the name and version of the app:
`javascript`
const options = {appInfo: { appName: 'sampleNodeTranslationApp', appVersion: '1.2.3' },};
const deepl = new deepl.DeepLClient('YOUR_AUTH_KEY', options);
This information is passed along when the library makes calls to the DeepL API.
Both name and version are required.
The DeepLClient constructor accepts configuration options as a second argument,
for example:
`javascript`
const options = { maxRetries: 5, minTimeout: 10000 };
const deepl = new deepl.DeepLClient('YOUR_AUTH_KEY', options);
The available options are:
- maxRetries: the maximum Number of failed HTTP requests to retry, perminTimeout
function call. By default, 5 retries are made. See
Request retries.
- : the Number of milliseconds used as connection timeout for eachserverUrl
HTTP request retry. The default value is 10000 (10 seconds).
- : string containing the URL of the DeepL API, can be overriddenheaders
for example for testing purposes. By default, the URL is selected based on the
user account type (free or paid).
- : extra HTTP headers attached to every HTTP request. By default, noproxy
extra headers are used. Note that Authorization and User-Agent headers are
added automatically but may be overridden by this option.
- : define the hostname, and port of the proxy server, and optionally
the protocol, and authorization (as an auth object with username and
password fields).
To rephrase text, call rephraseText(). The first argument is a string containing the text you want to rephrase, or an array of strings if you want to rephrase multiple texts.
The second argument is the target language code. Language codes are case-insensitive strings, for example, 'de', 'fr', 'en'. The target language code can also be null to enable auto-detection of the target language.
The last two arguments, writingStyle and tone, are optional and specify the writing style and tone of the rephrased text. Possible values are defined in the WritingStyle and WritingTone enums.
rephraseText() returns a Promise that fulfills with an Improvement object or an array of Improvement objects corresponding to your input text(s). The Improvement object has the following properties:text
- : the rephrased text,detectedSourceLang
- : the detected source language code,targetLanguage
- : the target language code.
`javascript
// Rephrasing a text in academic style:
const rephrasedResult = await deepLClient.rephraseText('This is an example text.', 'en', WritingStyle.ACADEMIC);
console.log(rephrasedResult.text); // The rephrased text in academic style
// Rephrasing multiple texts in a friendly tone:
const rephrasedTexts = await deepLClient.rephraseText(
['How are you?', 'What are you doing today?'],
'de',
null,
WritingTone.FRIENDLY,
);
console.log(rephrasedTexts[0].text); // The rephrased text for "How are you?" in a friendly tone
console.log(rephrasedTexts[1].text); // The rephrased text for "What are you doing today?" in a friendly tone
`
#### Logging
deepl-node logs debug and info messages for every HTTP request and responseloglevel
using the module, to the 'deepl' logger. You can reconfigure the
log level as follows:
`javascript
import log from 'loglevel';
log.getLogger('deepl').setLevel('debug'); // Or 'info'
`
The loglevel package also supports plugins, see
the documentation.
#### Proxy configuration
You can configure a proxy by specifying the proxy argument when constructing adeepl.DeepLClient:
`javascript`
const options = {proxy: {host: 'localhost', port: 3000}};
const deepl = new deepl.DeepLClient('YOUR_AUTH_KEY', options);
The proxy argument is passed to the underlying axios request, see the
[documentation for axios][axios-proxy-docs].
#### Anonymous platform information
By default, we send some basic information about the platform the client library
is running on with each request, see here for an explanation.
This data is completely anonymous and only used to improve our product, not track
any individual users. If you do not wish to send this data, you can opt-out when
creating your DeepLClient object by setting the sendPlatformInfo flag inDeepLClientOptions
the to false like so:
`javascript`
const options = {sendPlatformInfo: false};
const deepl = new deepl.DeepLClient('YOUR_AUTH_KEY', options);
Requests to the DeepL API that fail due to transient conditions (for example,
network timeouts or high server-load) will be retried. The maximum number of
retries can be configured when constructing the DeepLClient object using themaxRetries option. The timeout for each request attempt may be controlledminTimeout
using the option. An exponential-backoff strategy is used, so
requests that fail multiple times will incur delays.
If you experience problems using the library, or would like to request a new
feature, please open an [issue][issues].
We welcome Pull Requests, please read the
contributing guidelines.
There are multiple ways to manage your own environment variables. You can choose what works best for you. Make sure that only the values for one stage (local, prod, etc) are active at one time.
Using a global .rc file (such as ~/.bashrc):
`sh`Local
export DEEPL_MOCK_SERVER_PORT=3000
export DEEPL_AUTH_KEY=ANY_VALUE
export DEEPL_SERVER_URL=http://localhost:3000
`shunset DEEPL_MOCK_SERVER_PORTProd
(Make sure to run
if it was previously assigned a value)`
export DEEPL_AUTH_KEY={YOUR_API_KEY}
export DEEPL_SERVER_URL=https://api.deepl.com
Using .env file:
(Benefits include: No need to refresh terminal when changing stages, no need to call unset to clear vars, can be used to isolate vars between multiple projects)
- Copy .env.example file to a .env file .env
- The file will never be stored in git, so your local credentials will not be shared.env
- Edit file to your own desired variables
- If using local mock server, then point to local ports
Execute the tests using npm test. The tests communicate with the DeepL APIDEEPL_AUTH_KEY
using the authentication key defined by the environment
variable.
Be aware that the tests make DeepL API requests that contribute toward your API
usage.
The test suite may instead be configured to communicate with the mock-server
provided by [deepl-mock][deepl-mock]. Although most test cases work for either,
some test cases work only with the DeepL API or the mock-server and will be
otherwise skipped. The test cases that require the mock-server trigger server
errors and test the client error-handling. To execute the tests using
deepl-mock, run it in another terminal while executing the tests. Execute the
tests using npm test with the DEEPL_MOCK_SERVER_PORT and DEEPL_SERVER_URL`
environment variables defined referring to the mock-server.
[api-docs]: https://www.deepl.com/docs-api?utm_source=github&utm_medium=github-nodejs-readme
[api-docs-context-param]: https://www.deepl.com/docs-api/translating-text/?utm_source=github&utm_medium=github-nodejs-readme
[api-docs-csv-format]: https://www.deepl.com/docs-api/managing-glossaries/supported-glossary-formats/?utm_source=github&utm_medium=github-nodejs-readme
[axios-proxy-docs]: https://axios-http.com/docs/req_config
[create-account]: https://www.deepl.com/pro?utm_source=github&utm_medium=github-nodejs-readme#developer
[deepl-mock]: https://www.github.com/DeepLcom/deepl-mock
[issues]: https://www.github.com/DeepLcom/deepl-node/issues
[node-version-list]: https://nodejs.dev/en/about/releases/
[pro-account]: https://www.deepl.com/pro-account/?utm_source=github&utm_medium=github-nodejs-readme