Skip to content

Commit

Permalink
added app example
Browse files Browse the repository at this point in the history
  • Loading branch information
hexkode committed Aug 10, 2019
1 parent a33029b commit f37c5e7
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,46 @@ const configMap = {
COERCE_DISABLED: { coerceNull: false, coerceUndefined: false },
};
```

## App Example
.env
```js
NODE_ENV=test
LOG_LEVEL=debug
APP_NAME=env-config-map

SERVER_PORT=8080
```

config.js
```js
require('dotenv').config();
const envConfigMap = require('env-config-map');

const configMap = {
NODE_ENV: { default: 'development' },
LOG_LEVEL: { default: 'info' },
APP_NAME: { default: 'noname' },
SERVER_HOST: { default: 'localhost' },
SERVER_PORT: { default: 80, type: 'number' },
};
const config = envConfigMap(configMap);

module.exports = config;
```

server.js
```js
const http = require('http');
const config = require('./config.js');

http
.createServer((req, res) => {
res.write(`Hello ${config.APP_NAME}!`);
res.end();
})
.listen(
config.SERVER_PORT,
config.SERVER_HOST,
() => console.log(`server listening on ${config.SERVER_HOST}:${config.SERVER_PORT}`));
```

0 comments on commit f37c5e7

Please sign in to comment.