ConfigShip is a lightweight, package-safe configuration resolver that layers defaults, root config, environment variables, and runtime overrides.
Designed for apps and npm packages.
- Layered config resolution - defaults → file → env → runtime
- Nested ENV support - use
__for nested keys (e.g.,APP_DB__HOST) - Raw env names - access vars by original name (
APP_NAME) or transformed (name) - Auto-parsing - booleans, numbers, JSON automatically parsed
- Runtime overrides - dynamically update config at runtime
- TypeScript support - built with strict mode enabled
- Secure - protected against prototype pollution
- Zero dependencies - lightweight and fast
- No validation - simple and flexible
- No crashes - graceful fallbacks
runtime → env → file → defaults
npm install config-shipimport { createConfig } from "config-ship"
const config = createConfig({
defaults: {
db: { host: "localhost", port: 5432 }
},
envPrefix: "APP_",
rootFile: "app.config.ts"
})
config.get("db.host") // "localhost"
config.set("db.host", "127.0.0.1")Use double underscores (__) for nested keys. After the prefix, the first underscore separates the prefix, then __ creates nested paths:
# .env or environment
APP_DB__HOST=production.db.com # becomes db.host
APP_DB__PORT=3306 # becomes db.port
APP_FEATURE__ENABLED=true # becomes feature.enabledconst config = createConfig({
defaults: { db: { host: "localhost" } },
envPrefix: "APP_",
envFile: ".env"
})
config.get("db.host") // "production.db.com"
config.get("feature.enabled") // true (auto-parsed)
// You can also use raw env names
config.get("APP_DB__HOST") // "production.db.com"
config.get("APP_FEATURE__ENABLED") // trueSupports multiple formats:
JSON (app.config.json):
{
"db": {
"host": "staging.db.com"
}
}JavaScript (app.config.js):
export default {
db: {
host: "staging.db.com"
}
}TypeScript (app.config.ts):
export default {
db: {
host: "staging.db.com" as string
}
}const config = createConfig({
defaults: { db: { host: "localhost" } }
})
// Override at runtime
config.set("db.host", "custom.db.com")
config.get("db.host") // "custom.db.com"config.get(path, fallback?)- Get value at path, with optional fallbackconfig.set(path, value)- Set value at runtimeconfig.has(path)- Check if path existsconfig.all()- Get entire config object
- Raw env names: Access environment variables using original names (e.g.,
APP_NAME) or transformed names (e.g.,name) - Security: Fixed prototype pollution vulnerability in deep merge
- TypeScript: Enabled strict mode for better type safety
- Documentation: Added comprehensive examples and MIT license
MIT - see LICENSE file for details