0.1.0 • Published 6 years ago
shell-script-reader v0.1.0
Shell Script Reader
Shell Script Reader provides a way to read user customized shell script where a lot of enviromental vairables 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 enviromental variable sets for each projects respectively. These way you will be eased by multiple projects and tests for various configurations.
And still you can easily interacting with shell vairaibles.
Install
npm install --save shell-script-readerUsage
Import
import { ShellScriptReader } from "shell-script-reader";Initialize
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.comOnly
^exportstated lines are read.
We will have an env object:
{ AAA: '111',
BBB: 'sosoisidoeod',
ENV: 'E-SS OS',
UN: '',
AAAAA: '' }Read process.env
It provides access to process.env for convenience sake.
const value = reader.getEnvRaw("KEY_NAME");Read Script Variables
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: '' }License
The MIT License (MIT)
0.1.0
6 years ago