@edirect/config 11.0.48 → 11.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/dist/README.md +4 -94
- package/dist/package.json +3 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -54,11 +54,11 @@ export class MyService {
|
|
|
54
54
|
|
|
55
55
|
### `ConfigService`
|
|
56
56
|
|
|
57
|
-
| Method
|
|
58
|
-
|
|
59
|
-
| `constructor` | `(filePath?: string)`
|
|
60
|
-
| `get`
|
|
61
|
-
| `getConfig`
|
|
57
|
+
| Method | Signature | Description |
|
|
58
|
+
| ------------- | ------------------------------------ | ---------------------------------------------------------------------------------------------- |
|
|
59
|
+
| `constructor` | `(filePath?: string)` | Optionally pass a `.env` file path. Automatically called with `.{NODE_ENV}.env` by the module. |
|
|
60
|
+
| `get` | `(key: string): string \| undefined` | Returns the value for the given environment variable key from `process.env`. |
|
|
61
|
+
| `getConfig` | `(): IStringMapper` | Returns all environment variables as a `Record<string, string>`. |
|
|
62
62
|
|
|
63
63
|
### `CONFIG_SERVICE_TOKEN`
|
|
64
64
|
|
|
@@ -75,12 +75,12 @@ constructor(@Inject(CONFIG_SERVICE_TOKEN) private config: ConfigService) {}
|
|
|
75
75
|
|
|
76
76
|
The module automatically loads `.{NODE_ENV}.env` from the working directory:
|
|
77
77
|
|
|
78
|
-
| `NODE_ENV`
|
|
79
|
-
|
|
78
|
+
| `NODE_ENV` | File loaded |
|
|
79
|
+
| ----------------------- | ------------------ |
|
|
80
80
|
| `development` (default) | `.development.env` |
|
|
81
|
-
| `staging`
|
|
82
|
-
| `production`
|
|
83
|
-
| `test`
|
|
81
|
+
| `staging` | `.staging.env` |
|
|
82
|
+
| `production` | `.production.env` |
|
|
83
|
+
| `test` | `.test.env` |
|
|
84
84
|
|
|
85
85
|
**Example `.development.env`:**
|
|
86
86
|
|
package/dist/README.md
CHANGED
|
@@ -1,103 +1,13 @@
|
|
|
1
1
|
# @edirect/config
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- Loads `.{NODE_ENV}.env` file automatically on startup (e.g., `.development.env`, `.production.env`)
|
|
8
|
-
- Global module — register once, inject `ConfigService` anywhere
|
|
9
|
-
- Simple `get(key)` / `getConfig()` API
|
|
10
|
-
- Dual injection tokens: class token (`ConfigService`) and string constant (`CONFIG_SERVICE_TOKEN`)
|
|
3
|
+
The EDirectInsure Configuration Module.
|
|
11
4
|
|
|
12
5
|
## Installation
|
|
13
6
|
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
# or
|
|
17
|
-
npm install @edirect/config
|
|
7
|
+
```shell
|
|
8
|
+
$ npm i --save @edirect/config
|
|
18
9
|
```
|
|
19
10
|
|
|
20
11
|
## Usage
|
|
21
12
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
```ts
|
|
25
|
-
import { Module } from '@nestjs/common';
|
|
26
|
-
import { ConfigModule } from '@edirect/config';
|
|
27
|
-
|
|
28
|
-
@Module({
|
|
29
|
-
imports: [ConfigModule],
|
|
30
|
-
})
|
|
31
|
-
export class AppModule {}
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Because `ConfigModule` is decorated with `@Global()`, you only need to import it once at the root module. `ConfigService` will be available for injection in all feature modules automatically.
|
|
35
|
-
|
|
36
|
-
### Inject ConfigService
|
|
37
|
-
|
|
38
|
-
```ts
|
|
39
|
-
import { Injectable } from '@nestjs/common';
|
|
40
|
-
import { ConfigService } from '@edirect/config';
|
|
41
|
-
|
|
42
|
-
@Injectable()
|
|
43
|
-
export class MyService {
|
|
44
|
-
constructor(private readonly config: ConfigService) {}
|
|
45
|
-
|
|
46
|
-
doSomething() {
|
|
47
|
-
const dbUrl = this.config.get('DATABASE_URL');
|
|
48
|
-
const port = this.config.get('PORT') ?? '3000';
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## API
|
|
54
|
-
|
|
55
|
-
### `ConfigService`
|
|
56
|
-
|
|
57
|
-
| Method | Signature | Description |
|
|
58
|
-
|--------|-----------|-------------|
|
|
59
|
-
| `constructor` | `(filePath?: string)` | Optionally pass a `.env` file path. Automatically called with `.{NODE_ENV}.env` by the module. |
|
|
60
|
-
| `get` | `(key: string): string \| undefined` | Returns the value for the given environment variable key from `process.env`. |
|
|
61
|
-
| `getConfig` | `(): IStringMapper` | Returns all environment variables as a `Record<string, string>`. |
|
|
62
|
-
|
|
63
|
-
### `CONFIG_SERVICE_TOKEN`
|
|
64
|
-
|
|
65
|
-
An alternative injection token (string constant) for `ConfigService`. Useful when you need to inject by token rather than by class:
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
import { Inject } from '@nestjs/common';
|
|
69
|
-
import { CONFIG_SERVICE_TOKEN, ConfigService } from '@edirect/config';
|
|
70
|
-
|
|
71
|
-
constructor(@Inject(CONFIG_SERVICE_TOKEN) private config: ConfigService) {}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## Environment File Convention
|
|
75
|
-
|
|
76
|
-
The module automatically loads `.{NODE_ENV}.env` from the working directory:
|
|
77
|
-
|
|
78
|
-
| `NODE_ENV` | File loaded |
|
|
79
|
-
|------------|-------------|
|
|
80
|
-
| `development` (default) | `.development.env` |
|
|
81
|
-
| `staging` | `.staging.env` |
|
|
82
|
-
| `production` | `.production.env` |
|
|
83
|
-
| `test` | `.test.env` |
|
|
84
|
-
|
|
85
|
-
**Example `.development.env`:**
|
|
86
|
-
|
|
87
|
-
```env
|
|
88
|
-
PORT=3000
|
|
89
|
-
DATABASE_URL=mongodb://localhost:27017/mydb
|
|
90
|
-
REDIS_URL=redis://localhost:6379
|
|
91
|
-
LOGS_LEVEL=debug
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
> **Note:** Never commit `.env` files containing sensitive credentials to version control.
|
|
95
|
-
|
|
96
|
-
## Exports
|
|
97
|
-
|
|
98
|
-
```ts
|
|
99
|
-
export { ConfigModule } from './config/config.module';
|
|
100
|
-
export { ConfigService } from './config/config.service';
|
|
101
|
-
export { CONFIG_SERVICE_TOKEN } from './config/config.constants';
|
|
102
|
-
export type { IStringMapper } from './config/config.interfaces';
|
|
103
|
-
```
|
|
13
|
+
Import ConfigModule on AppModule (app.module.ts)
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edirect/config",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.46",
|
|
4
4
|
"main": "./dist/src/index.js",
|
|
5
5
|
"types": "./dist/src/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@nestjs/common": "^11.1.
|
|
20
|
-
"dotenv": "17.3
|
|
19
|
+
"@nestjs/common": "^11.1.12",
|
|
20
|
+
"dotenv": "17.2.3",
|
|
21
21
|
"tslib": "^2.8.1"
|
|
22
22
|
},
|
|
23
23
|
"type": "commonjs"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edirect/config",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.50",
|
|
4
4
|
"packageScope": "@edirect",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"types": "./dist/src/index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@nestjs/common": "^11.1.
|
|
20
|
+
"@nestjs/common": "^11.1.16",
|
|
21
21
|
"dotenv": "17.3.1",
|
|
22
22
|
"tslib": "^2.8.1"
|
|
23
23
|
},
|