1.1.0 • Published 10 months ago

envweb v1.1.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
10 months ago

envweb

Tiny app that serves environment variables as a javascript.

Features

  • Zero dependencies
  • Only allowed envs are exposed
  • Throws if env is not defined

Usage

Create .env file:

PARAM=VALUE

NO_DEFAULT_VALUE
# COMMENTED

Run the app:

npx envweb

Configure reverse-proxy (optional, nginx example):

location /config.js {
    proxy_pass http://path/to/envweb/;
}

Include generated script (before the main app):

<script src="config.js"></script>

Use in your app:

console.log(CONFIG.PARAM); // Equals to VALUE or can be overriten in the env

JSON mode

If you run the app with --json flag, it will return json instead of script. So you can use it in your app like this:

fetch('config.json')
    .then(response => response.json())
    .then(config => console.log(config.PARAM));

CLI arguments

Each argument can be passed as a flag or as a value (e.g. --port 8080 or --port=8080). Arguments have short aliases (e.g. -p 8080)

ParameterTypeDefaultDescription
portstring8080Port where app is serverd
filestring.envEnv filename to read
variablestringCONFIGName of variable in global script
windowbooleanfalseIf variable should be set to window
compressbooleanfalseIf script should be one-line
jsonbooleanfalseResponse as json instead of script. (-v and -w are forbidden)

Contributing

Contributions are always welcome!

License

Apache-2.0

1.1.0

10 months ago

1.0.1

10 months ago