https://github.com/french-exception/node-config-api
Configuration API
https://github.com/french-exception/node-config-api
Last synced: over 1 year ago
JSON representation
Configuration API
- Host: GitHub
- URL: https://github.com/french-exception/node-config-api
- Owner: French-Exception
- Created: 2020-01-18T21:06:17.000Z (over 6 years ago)
- Default Branch: develop
- Last Pushed: 2023-03-04T05:44:12.000Z (over 3 years ago)
- Last Synced: 2025-03-17T22:59:43.026Z (over 1 year ago)
- Language: TypeScript
- Size: 377 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# About
Configuration API let you use Configuration Lib with your own code.
It helps create and load User-scoped, Global-scoped and Directory-scoped Configuration files.
Configuration files can be ```.json``` or ```.js``` files returning plain JSON or
# Installation
```bash
npm i --save @frenchex/config-api
```
# Usage
## From File
Example loading from file (from tests) :
```typescript
import * as api from "@frenchex/config-api"
const config = await api.fromFile({
env: {env: 'dev'},
file: path.join(testResourcesRootPath, 'js.js'),
root: testResourcesRootPath
})
const foobar = await config.get('foo.bar');
const foobar2 = await config.get('foo.foobar');
const foo = await config.get<{ bar: string, foobar: string }>('foo');
const promise = await config.get('promise');
expect(foobar).to.be.equal('foobar');
expect(foobar2).to.be.equal('foobarfoobar');
expect(foo).to.be.deep.equal({bar: 'foobar', foobar: 'foobarfoobar'});
expect(promise).to.be.deep.equal('resolved');
```
## From JS object
Example loading config from object (from tests):
```typescript
const config = await api.fromDeclaration({
$: {
foo: {
bar: 'foobar'
}
}
})
const bar = await config.get('foo.bar');
expect(bar).to.be.equal('foobar');
```
## From File & JS object
You can also do both
````typescript
const config = await api.fromFile({
env: {env: 'dev'},
file: path.join(testResourcesRootPath, 'js.js'),
root: testResourcesRootPath,
$: {
"imports": ['my_file_%env%.json'],
}
})
````