Load environment variables from the cloud, using the cenv-registry. cenv may be used as a cli tool from a terminal to load an environment against a command, or as a library in your Node.js application to load your environment dynamically.
$ npm install cenv
Usage: cenv [options] <environment> <command...>
Options:
-V, --version output the version number
-f, --file [file_path] Config file path
-r, --registry [registry_url] Registry url
-u, --username [username] Registry username
-p, --password [password] Registry password
-t, --token [token] Registry authenticated token
-o, --timeout [timeout] Registry connection timeout
-h, --help output usage information
cenv depends on it's registry to work. You can download and configure your own registry following the instructions in this repository.
- *environment - Environment to retrieve from the registry
- *command - Command that will be executed after the environment is loaded
- -V, --version - Output the version number
- -f, --file [file_path] - Sets the config file path
- -r, --registry [registry_url] - Sets the cenv-registry url
- This option overwrites config file registry
- -u, --username [username] - Sets registry username
- This option overwrites config file username
- -p, --password [password] - Sets registry password
- This option overwrites config file password
- -t, --token [token] - Sets registry authenticated token
- This option overwrites config file token
- -o, --timeout [timeout] - Sets registry request timeout in milliseconds
- Defaults to 1000
- This option overwrites config file timeout
- -h, --help [timeout] - Output usage information
const cenv = require('cenv');
// cenv returns a promise, so you can wait for the environment to be loaded
cenv('myenv', { file: '../.cenv.yml' })
.then(() => {
console.log(process.env.myenv); // myvalue
});
// You can also set an interval to update your application's environment from time to time
setInterval(() => cenv('anotherenv', { file: '../.cenv.json' }), 300000);
Licence © Rodrigo Gomes da Silva