3.0.40 • Published 2 months ago

@trenskow/config v3.0.40

Weekly downloads
1
License
MIT
Repository
github
Last release
2 months ago

@trenskow/config

Converts process.env into a neatly packed object.

Usage

import config from '@trenskow/config';

const myConfig = await config();

What it does

It turns the environment variables below...

API_PORT=3000
API_BASE_URL="http://api.myapp.com/"
API_AUTH_TOKEN=myauthtoken
API_USER_KEYS_0="key1"
API_USER_KEYS_1="key2"
API_USER_KEYS_2="key3"

...into the data below.

{
	api: {
		port: '3000',
		baseUrl: 'http://api.myapp.com',
		authToken: 'myauthtoken',
		userKeys: [
			'key1',
			'key2',
			'key3'
		]
	}
}

Validation

The isvalid package is build into the library and can be used to validate the configuration.

See the documentation for isvalid on how to format the schema.

Example

const myConfig = await config({
	'port': {
		type: Number,
		required: true,
		range: '-65535'
	}
}, /* options = { defaults: { unknownKeys: 'allow' } } */);

The above example will throw an error if the data cannot be validated. It will, though, because of the way isvalid works, convert the port to a Number.

See the isvalid documentation for available options.

The comment in the example is there to show what options config uses per default.

License

See license in LICENSE.

3.0.40

2 months ago

3.0.39

2 months ago

3.0.35

2 months ago

3.0.38

2 months ago

3.0.36

2 months ago

3.0.37

2 months ago

3.0.34

2 months ago

3.0.32

2 months ago

3.0.33

2 months ago

3.0.27

3 months ago

3.0.30

3 months ago

3.0.31

3 months ago

3.0.29

3 months ago

3.0.23

4 months ago

3.0.24

4 months ago

3.0.25

4 months ago

3.0.26

4 months ago

3.0.12

10 months ago

3.0.13

10 months ago

3.0.10

10 months ago

3.0.11

10 months ago

3.0.16

9 months ago

3.0.8

10 months ago

3.0.17

9 months ago

3.0.7

10 months ago

3.0.14

9 months ago

3.0.15

9 months ago

3.0.21

6 months ago

3.0.22

6 months ago

3.0.20

7 months ago

3.0.18

7 months ago

3.0.19

7 months ago

3.0.9

10 months ago

3.0.6

1 year ago

3.0.5

1 year ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.1.6

2 years ago

2.1.8

2 years ago

2.1.7

2 years ago

2.1.9

2 years ago

2.1.12

2 years ago

2.1.10

2 years ago

2.1.11

2 years ago

2.1.5

2 years ago

2.1.2

3 years ago

2.1.4

3 years ago

2.1.1

3 years ago

2.0.0

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago