This package has been deprecated

Author message:

Migration to Deno

nvee
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Nvee

Say 'envy'

TL;DR

.gitignore

/config/*.env
!/config/public.env

/config/public.env

MONGO_ADMIN_NAME=admin

mycode.js

import Nvee from 'nvee'

console.log(Nvee.MONGO_ADMIN_NAME)

What am I?

The well-known dotenv does almost what I want, but not quite.

  • Config files should not, by default, litter the root directory of a project. They should be under /config
  • Once config files are moved to /config, there's no point in 'hiding' them
  • We need one 'configuration set' for development and another, per environment, for 'near production' and production. (Near production environments are intermediate environments between dev and prod where we don't want to expose configuration to the outside world)
  • Configuration sets should cascade so that, when running tests, I only have to override certain items
  • Configuration should be checked to be complete
  • No code changes are needed to change configuration file selection

Where is the config/ directory?

Nvee assumes the the current working directory is in the project tree and seaches in process.cwd(), then the parent and so on until it finds config/public.env or runs out of directories.

File naming convention

General format: ''' [ 'public' | 'private' ] (.name)? '.env' ''' Examples

  • public.env: Nonsensitive configuration
  • public.myname.env: Nonsensitive configuration related to 'myname' - a 'named file'
  • private.env: Production configuration contains sensitive configuration

Configuration sets

Public configuration sets may be checked into source control sustem like Git, private configuration should never be checked in with code.

In a Node project Nvee needs the /config/public.env file which acts as a foundation for all other application congfiguration. All other configuration sets are layered on top of public.env.

File format

  • Files are read line by line
  • Leading and trailing white space is discarded
  • Empty lines and lines starting with '#' are discarded
  • Remaing lines are in the format key '=' value1 where...
    • key: [A-Za-z_][A-Za-z0-9_]*
    • value: [^\n\r]*
  • Values are trimmed and may be empty
  • Keys must be unique

There is currently no support for escaping and multi-line values

File layering

File selection

  • public.env is required, other files are optional. If the file is not found then an error is emmitted and the process aborted
  • Nvee looks for private.env, if it is present then no files are selected
  • If the environment variable NVEE is set then its value is used to select public.<value>.env. If present it is selected. In any case file selection ends
  • Only one file is allowed with a given name, that is if /config contains both public.x.env and private.x.env an exception will be thrown
  • If there are multiple named files then the first is selected where the file name is sorted alphabettically

After this process public.env will have been found optionally with a file to be layered on top.

File layering

  • If no layering file was found then the configuration from public.env is used 'as-is'
  • Key check: the set of keys in the base and layered file must match otherwise an exception is thrown. This avoids production configuration files getting out of synch
  • Key/values from the base file are loaded into a map
  • Keys/values in the layering file that have values are put into the map (displacing base file pairs)

Readme

Keywords

Package Sidebar

Install

npm i nvee

Weekly Downloads

0

Version

1.0.2

License

Copyright (C) Keith Whittingham 2021, all rights reserved

Unpacked Size

11.6 kB

Total Files

5

Last publish

Collaborators

  • npm
  • kwhitty