1.0.0 • Published 11 months ago
betterconf v1.0.0
Betterconf
Use .conf configuration files and generate a TypeScript file.
Installation
With NPM:
npm install betterconfWith PNPM:
pnpm install betterconfWith Bun:
bun install betterconfGetting started
betterconf support .conf file with the Hocon specs. Here a short sample with dev and prod conf:
# config.dev.conf
{
env = ${NODE_ENV} # development
database {
provider = "sqlite"
url = "file:./dev.db"
}
}# config.prod.conf
{
env = ${NODE_ENV} # production
database {
provider = "postgres"
url = "postgresql://postgres:postgres@localhost:5432/postgres"
}
}Add betterconf to your package's scripts (Next.js example here):
"scripts": {
"dev": "betterconf run -r='config.dev.conf' -w='src/config.ts' -- next dev",
"build": "betterconf run -r='config.prod.conf' -w='src/config.ts' -- next build",
...
}And use it anywhere from your code source:
import { config } from "./config"
console.log(config.env) // "development"
console.log(config.database.provider) // "sqlite"
console.log(config.database.url) // "file:./dev.db"Copyright
© Christophe Ribeiro under MIT License.