calidion / shell-script-reader

use process.env locally

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

Coverage Status MIT license

Shell Script Reader

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.

Install

npm install --save shell-script-reader

Usage

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.com

Only ^export started 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)

About

use process.env locally

License:MIT License


Languages

Language:TypeScript 100.0%