pamplemousse

Introduction

This is a port of node-config that does hierarchical configuration. It allows you define a set of default values and extend them for different environments. It does not contain all the features of node-config but feel free to submit a PR or suggest one to implement.

Features supported:

Features not supported:

  • specifying config directory (It's always ./config)
  • recursion detection
  • YAML, JS, XML, etc. parsing formats
  • instance names
  • hostnames

Usage

If you would like to use the default options, simply import your configuration like this:

import config from "https://deno.land/x/pamplemousse/mod.ts";

And access the config variables using config.has() and config.get(). Optionally, you can use the shorthand, config.varname or config.nested.varname but this has no protection for typos.

If you'd like to pass in environment variables via code, for example, if you want to set the NODE_ENV in code, you can do something like this:

import { Config } from "https://deno.land/x/pamplemousse/config.ts";
const config = await new Config({
    env: {
        "NODE_ENV": "dev",
    }
});

When running your app, you must allow read access to the ./config directory, like so:

deno run --allow-read=config app.ts

If you fail to do so, Deno will prompt you to allow access in the CLI:

$ deno run app.ts
⚠️  ️Deno requests read access to "config". Run again with --allow-read to bypass this prompt.
   Allow? [y/n (y = yes allow, n = no deny)]

If you pass in environment variables, you should add --allow-env to correctly read them.

You can allow all environment variables:

NODE_ENV=staging deno run --allow-env --allow-read=config app.ts

Or specific ones:

NODE_ENV=staging deno run --allow-env=NODE_ENV --allow-read=config app.ts