Shell Script Reader provides a way to read user customized shell script where a lot of environmental variables are defined.
So you can easily share your shell variables with your node.js scripts.
Instead of using a central process.env, you can use your environmental variable sets for each projects respectively. These way you will be eased from multiple projects and tests for various configurations.
And still you can easily interacting with shell variables.
npm install --save shell-script-reader
import { ShellScriptReader } from "shell-script-reader";
import * as path from "path";
const filename = path.resolve(__dirname, "./env");
const reader = new ShellScriptReader(filename);
env
file example:
export AAA=111
export BBB=sosoisidoeod
export ENV=E-SS OS
export UN=
export UN=aaasossos=aaa
export AAAAA
export
export
# SHELL COMMENTS
wget https://www.google.com
Only
^export
started lines are read.
We will have an env object:
{ AAA: '111',
BBB: 'sosoisidoeod',
ENV: 'E-SS OS',
UN: '',
AAAAA: '' }
It provides access to process.env for convenience sake.
const value = reader.getEnvRaw("KEY_NAME");
const value = reader.getEnv("KEY_NAME");
For ./env
script defined above:
const value = reader.getEnv("AAA");
// '111'
const value = reader.getEnv("BBB");
// 'sosoisidoeod'
If no key is provided, the whole object will be returned:
const value = reader.getEnv();
// { AAA: '111',
// BBB: 'sosoisidoeod',
// ENV: 'E-SS OS',
// UN: '',
// AAAAA: '' }
The MIT License (MIT)