diff --git a/README.md b/README.md index abb6c28..1bb5fce 100644 --- a/README.md +++ b/README.md @@ -167,45 +167,52 @@ In the above case even if the `default.json` has a port setting of `9000` the cl 3. **Warnings & Errors:** [node-config] relies on calling the `get` and the `has` methods to issue errors. This is unsafe typically when the configurations are different between your dev and production environments. With `node-config-ts` you can trust the typescript compiler to issue an error immediately when you try to access a property that isn't defined anywhere. Consider the following case — - #### default.json - ```json - { - "port": 3000 - } - ``` - #### user/john.json - ```json - { - "baseURL": "/api" - } - ``` - - In the above case the final configuration *should* look something like this on `john`'s local machine — - - ```json - { - "port": 3000, - "baseURL": "/api" - } - ``` - - ##### reading using node-config: - ```ts - import config from 'config' - - console.log(config.get('port')) - console.log(config.get('baseURL')) // works locally but fails in production - ``` - This would work when `john` is running the application on his local machine. But as soon as its deployed in production the configuration property `baseURL` isn't available anymore and it results in runtime exceptions. - - ##### using node-config-ts: - ```ts - import {config} from 'node-config-ts' - - console.log(config.port) // proper intellisense support - console.log(config.baseURL) // throws compile time error immediately on local machine. - ``` - Because the above object `config`, is exposed with proper typings, using invalid configurations results in typescript errors. This would happen on both — `john`'s computer and the production server. +#### default.json + +```json +{ + "port": 3000 +} +``` + +#### user/john.json + +```json +{ + "baseURL": "/api" +} +``` + +In the above case the final configuration _should_ look something like this on `john`'s local machine — + +```json +{ + "port": 3000, + "baseURL": "/api" +} +``` + +##### reading using node-config: + +```ts +import config from 'config' + +console.log(config.get('port')) +console.log(config.get('baseURL')) // works locally but fails in production +``` + +This would work when `john` is running the application on his local machine. But as soon as its deployed in production the configuration property `baseURL` isn't available anymore and it results in runtime exceptions. + +##### using node-config-ts: + +```ts +import {config} from 'node-config-ts' + +console.log(config.port) // proper intellisense support +console.log(config.baseURL) // throws compile time error immediately on local machine. +``` + +Because the above object `config`, is exposed with proper typings, using invalid configurations results in typescript errors. This would happen on both — `john`'s computer and the production server. [node-config]: https://github.com/lorenwest/node-config [reserved words]: https://github.com/lorenwest/node-config/wiki/Reserved-Words