Skip to content

Commit 919f0b4

Browse files
committed
Simple configuration example
1 parent 55a7c47 commit 919f0b4

File tree

6 files changed

+46
-0
lines changed

6 files changed

+46
-0
lines changed

nodeconfig/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
NODE_CONFIG_DIR=./config
2+
NODE_ENV=production

nodeconfig/config/default.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"app": {
3+
"port": 3000
4+
},
5+
"db": {
6+
"host": "localhost",
7+
"port": 27017,
8+
"name": "ydb"
9+
}
10+
}

nodeconfig/config/default.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
app:
2+
port: 3000
3+
4+
db:
5+
host: localhost
6+
port: 27017
7+
name: ydb

nodeconfig/config/production.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
app:
2+
port: 3300
3+
4+
db:
5+
host: localhost
6+
port: 27017
7+
name: mydb

nodeconfig/dotenv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
NODE_CONFIG_DIR=./config
2+
NODE_ENV=[development|production]
3+

nodeconfig/simple.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env node
2+
require("dotenv").config();
3+
const config = require("config");
4+
5+
let appPort = config.get("app.port");
6+
console.log(`Application port: ${appPort}`);
7+
8+
let dbHost = config.get("db.host");
9+
console.log(`Database host: ${dbHost}`);
10+
11+
let dbPort = config.get("db.port");
12+
console.log(`Database port: ${dbPort}`);
13+
14+
let dbName = config.get("db.name");
15+
console.log(`Database name: ${dbName}`);
16+
17+
console.log("NODE_ENV: " + config.util.getEnv("NODE_ENV"));

0 commit comments

Comments
 (0)