configre 1.1.4 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/package.json +1 -1
- package/skills/configre/SKILL.md +113 -0
package/README.md
CHANGED
|
@@ -21,6 +21,11 @@ To get started with Configre, follow these steps:
|
|
|
21
21
|
npm install configre --save
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
> You can also add Configre as a skill for AI agentic development:
|
|
25
|
+
> ```bash
|
|
26
|
+
> npx skills add https://github.com/clasen/Configre --skill configre
|
|
27
|
+
> ```
|
|
28
|
+
|
|
24
29
|
2. **Setup Your Configuration Files**
|
|
25
30
|
|
|
26
31
|
Organize your configuration files within a directory (e.g., `config`). Create a default configuration file and environment-specific files as needed.
|
package/package.json
CHANGED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: configre
|
|
3
|
+
description: Set up and manage environment-specific configuration in Node.js projects using the Configre library. Use when the user wants to add configuration management, create environment configs, set up hostname-based settings, or mentions "configre", "config files", "environment config", or "per-host settings".
|
|
4
|
+
metadata:
|
|
5
|
+
category: configuration
|
|
6
|
+
tags: [nodejs, config, environment, settings, env]
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Configre
|
|
10
|
+
|
|
11
|
+
Environment-specific configuration manager for Node.js. Merges a default config with hostname or profile-based overrides using deep merge (lodash).
|
|
12
|
+
|
|
13
|
+
## Instructions
|
|
14
|
+
|
|
15
|
+
### Step 1: Install the package
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install configre --save
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Step 2: Create the config directory
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
project/
|
|
25
|
+
├── config/
|
|
26
|
+
│ ├── index.js # Default settings (required)
|
|
27
|
+
│ ├── myhostname.js # Host-specific overrides (optional)
|
|
28
|
+
│ └── myhostname.dev.js # Dev override for host (optional)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
If the project uses `"type": "module"` in `package.json`, create `config/package.json`:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{ "type": "commonjs" }
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
This is needed because config files use `module.exports`.
|
|
38
|
+
|
|
39
|
+
### Step 3: Write the default config (`config/index.js`)
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
module.exports = {
|
|
43
|
+
db: {
|
|
44
|
+
host: 'localhost',
|
|
45
|
+
port: 5432,
|
|
46
|
+
user: 'dev',
|
|
47
|
+
password: 'dev-pass'
|
|
48
|
+
},
|
|
49
|
+
api: {
|
|
50
|
+
key: 'default-key',
|
|
51
|
+
url: 'http://localhost:3000'
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Step 4: Write host/profile overrides
|
|
57
|
+
|
|
58
|
+
Create `config/<hostname>.js` with only the keys that differ — they are deep-merged over defaults:
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
module.exports = {
|
|
62
|
+
db: {
|
|
63
|
+
user: 'prod-user',
|
|
64
|
+
password: 'prod-secret'
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Step 5: Load the configuration
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
const cfg = require("configre")();
|
|
73
|
+
|
|
74
|
+
console.log(cfg.db.host); // from default
|
|
75
|
+
console.log(cfg.db.user); // from host override
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
To use a custom config directory:
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
const cfg = require("configre")(__dirname + "/settings");
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Profile resolution
|
|
85
|
+
|
|
86
|
+
Configre determines the active profile from `process.argv[2]` (CLI argument) or `os.hostname()` as fallback. It then checks for overrides in this order (first match wins):
|
|
87
|
+
|
|
88
|
+
1. `config/<profile>.dev.js` or `.cjs` — dev override
|
|
89
|
+
2. `config/<profile>.js` or `.cjs` — production override
|
|
90
|
+
3. No match — uses defaults only
|
|
91
|
+
|
|
92
|
+
## Examples
|
|
93
|
+
|
|
94
|
+
**Example 1: Basic setup**
|
|
95
|
+
User says: "Add configuration management to my Node.js project"
|
|
96
|
+
Actions: install configre, create `config/index.js` with project defaults, load with `require("configre")()`
|
|
97
|
+
Result: merged config object ready to use
|
|
98
|
+
|
|
99
|
+
**Example 2: Multi-environment**
|
|
100
|
+
User says: "I need different database settings per server"
|
|
101
|
+
Actions: create `config/index.js` with defaults, create `config/<hostname>.js` per server with db overrides
|
|
102
|
+
Result: each server automatically loads its own config based on hostname
|
|
103
|
+
|
|
104
|
+
**Example 3: Custom profile via CLI**
|
|
105
|
+
User says: "I want to run my app with a staging config"
|
|
106
|
+
Actions: create `config/staging.js`, run app with `node app.js staging`
|
|
107
|
+
Result: staging overrides are merged over defaults
|
|
108
|
+
|
|
109
|
+
## Key behaviors
|
|
110
|
+
|
|
111
|
+
- **Deep merge**: nested objects merge recursively via lodash `_.merge`
|
|
112
|
+
- **Both `.js` and `.cjs`** extensions are supported for all config files
|
|
113
|
+
- **Function vs constructor**: `Configre(path)` returns the merged config directly; `new Configre(path)` returns the instance (use `.get()` to retrieve config)
|