Skip to content

Commit cb453f1

Browse files
committed
feat: Add .env.example and dotenv lib for environment management
1 parent 6435f09 commit cb453f1

File tree

7 files changed

+65
-2
lines changed

7 files changed

+65
-2
lines changed

.env.example

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Default
2+
DEEPL_AUTH_KEY= # Add your API key here
3+
4+
# Local
5+
# Below is the config for running the mock server in docker (https://github.com/DeepLcom/deepl-mock/)
6+
# DEEPL_MOCK_SERVER_PORT=3000
7+
# DEEPL_AUTH_KEY=PLACEHOLDER
8+
# DEEPL_SERVER_URL=http://localhost:3000
9+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ junit.xml
66
examples/**/package-lock.json
77
examples/**/.env
88
.DS_Store
9+
.env

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
87
## [Unreleased]
8+
### Added
9+
* Added .env.example file with `dotenv` library for environment variables management
10+
* Improve unit tests
11+
912
### Changed
1013
* Upgrade cross-spawn library (see https://github.com/advisories/GHSA-3xgq-45jj-v275)
1114

@@ -280,7 +283,7 @@ client library took over this package name. Thanks to
280283
ownership.
281284

282285

283-
[Unreleased]: https://github.com/DeepLcom/deepl-node/compare/v1.15.0...HEAD
286+
[Unreleased]: https://github.com/DeepLcom/deepl-node/compare/v1.16.0...HEAD
284287
[1.16.0]: https://github.com/DeepLcom/deepl-node/compare/v1.15.0...v1.16.0
285288
[1.15.0]: https://github.com/DeepLcom/deepl-node/compare/v1.14.0...v1.15.0
286289
[1.14.0]: https://github.com/DeepLcom/deepl-node/compare/v1.13.1...v1.14.0

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,35 @@ feature, please open an [issue][issues].
526526
We welcome Pull Requests, please read the
527527
[contributing guidelines](CONTRIBUTING.md).
528528

529+
### Environment Variables
530+
531+
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.
532+
533+
**Using a global .rc file (such as ~/.bashrc):**
534+
535+
```sh
536+
# Local
537+
export DEEPL_MOCK_SERVER_PORT=3000
538+
export DEEPL_AUTH_KEY=ANY_VALUE
539+
export DEEPL_SERVER_URL=http://localhost:3000
540+
```
541+
542+
```sh
543+
# Prod
544+
# (Make sure to run `unset DEEPL_MOCK_SERVER_PORT` if it was previously assigned a value)
545+
export DEEPL_AUTH_KEY={YOUR_API_KEY}
546+
export DEEPL_SERVER_URL=https://api.deepl.com
547+
```
548+
549+
**Using .env file**:
550+
551+
(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)
552+
553+
- Copy `.env.example` file to a `.env` file
554+
- The `.env` file will never be stored in git, so your local credentials will not be shared
555+
- Edit `.env` file to your own desired variables
556+
- If using local mock server, then point to local ports
557+
529558
### Tests
530559

531560
Execute the tests using `npm test`. The tests communicate with the DeepL API

package-lock.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"dependencies": {
2222
"@types/node": ">=12.0",
2323
"axios": "^1.7.4",
24+
"dotenv": "^16.4.7",
2425
"form-data": "^3.0.0",
2526
"loglevel": ">=1.6.2"
2627
},

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ import path from 'path';
5050
import * as os from 'os';
5151
import { URLSearchParams } from 'url';
5252
import * as util from 'util';
53+
import dotenv from 'dotenv';
54+
55+
dotenv.config(); // Load environment variables from .env file
5356

5457
export * from './errors';
5558
export * from './glossaryEntries';

0 commit comments

Comments
 (0)