Skip to content

Commit

Permalink
fix(doc): fix formatting for readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Nov 9, 2018
1 parent 4269e00 commit 0fb2683
Showing 1 changed file with 46 additions and 39 deletions.
85 changes: 46 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0fb2683

Please sign in to comment.