Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath authored Dec 30, 2017
1 parent adf3242 commit 6e59ac5
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ node-config-ts
[![Greenkeeper badge](https://badges.greenkeeper.io/tusharmath/node-config-ts.svg)](https://greenkeeper.io/)

A simple node configuration manager for typescript based projects.
It automatically generates typings for the project based on the default configuration.

**It automatically generates typings**

## Usage

Expand All @@ -28,7 +27,7 @@ It automatically generates typings for the project based on the default configur
root/
└── config/
└── default.json
```
```
`default.json` should contain your application's configuration

4. Create typings
Expand All @@ -38,6 +37,7 @@ It automatically generates typings for the project based on the default configur
A new `Config.d.ts` will be generated automatically. This file could be ignored from git as it gets automatically generated based on the structure of `default.json`

5. Import and use `node-config-ts`

```typescript
import {config} from 'node-config-ts'
Expand All @@ -46,22 +46,23 @@ It automatically generates typings for the project based on the default configur

## Directory Structure
Configurations are loaded via config files that are written in JSON format for now. A typical project looks like this —
```
root/
└── config/
├── Config.d.ts
├── default.json
├── deployment/
│ ├── staging.example.com.json
│ ├── production.example.com.json
│ └── qa.example.com.json
├── env/
│ └── production.json
└── user/
├── ec2-user.json
├── andy.json
└── sara.json
```

```
root/
└── config/
├── Config.d.ts
├── default.json
├── deployment/
│ ├── staging.example.com.json
│ ├── production.example.com.json
│ └── qa.example.com.json
├── env/
│ └── production.json
└── user/
├── ec2-user.json
├── andy.json
└── sara.json
```
There are three directories in which a project can have configurations — `deployment`, `env` and `user`. These directories can have multiple files inside them and based on the environment variables an appropriate config file is selected for overriding the base `default.json`. For instance if the `NODE_ENV` variable is set to `production` the `env/production.json` configuration will be merged with `default.json`. Similarly if `DEPLOYMENT` env variable is set to `staging.example.com` then `deployment/staging.example.com.json` is merged with the other configs. Here is a table for environment to directory mapping —
Expand All @@ -80,3 +81,17 @@ The configs are merged in the following order of priority —
2. User
3. Deployment
4. Environment
The command line arguments can override all the configuration params. This is useful when you want to start a node server by passing the port externally —
```bash
node server.js --port 3000
```

In the above case even if the `default.json` has a port setting of `9000` the cli argument can override it
```json
// default.json
{
"port": 9000
}
```

0 comments on commit 6e59ac5

Please sign in to comment.