1.0.3 • Published 3 years ago

@ehcan/envparser v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Env Parser

A simple module for parse env variables into required type.

Example:

const env = require('@ehcan/envparser');

config = {
	db: {
		host: env.str('DB_HOST', 'localhost'),
		port: env.num('DB_PORT', 5432),
		username: env.str('DB_USER', 'user_1'),
		password: env.str('DB_PASS', 'passwd'),
		queryLog: env.bool('DB_QUERY_LOG', true),
		options: env.array('DB_OPTIONS', ['option_1', 'option_2']),
	},
};

console.log(config);

Without env file:

console.log(config);

{
  "db": {
    "host": "localhost",
    "port": 5432,
    "username": "user_1",
    "password": "passwd",
    "queryLog": true,
    "options": [
      "option_1",
      "option_2"
    ]
  }
}

With env file:

DB_HOST=pg
DB_PORT=5400
DB_USER=my_user
DB_PASS=my_pass
DB_QUERY_LOG=false
DB_OPTIONS=option_3,option_4
console.log(config);

{
  "db": {
    "host": "pg",
    "port": 5400,
    "username": "my_user",
    "password": "my_pass",
    "queryLog": false,
    "options": [
      "option_3",
      "option_4"
    ]
  }
}
1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago