ngx-environment-variable
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

ngx-environment-variable

Angular x script to set environment variables like Node Js environment variables

  • Angular (Using "ngx-environment-variable"): ngxEnv.ENVIRONMENT_VARIABLE
  • Node: process.env.ENVIRONMENT_VARIABLE

installation

npm install ngx-environment-variable OR yarn add ngx-environment-variable

How to use ?

  1. Put declaration in src/typings.d.ts
declare var ngxEnv;
  1. Delete environment import statement and put following piece of code above the AppModule import statement in src/main.ts:
import setNgxEnv from 'ngx-environment-variable';
import { environment } from './environments/environment';
setNgxEnv(environment, { origin: 'http://localhost:4200' });
  1. Use ngxEnv to environemt variables defined in environment.ts inside component, directive, pipe and module class.
export class AppComponent {
  title = ngxEnv.FACEBOOK_APP_ID;
  ngOnInit() {
    console.log(ngxEnv.FACEBOOK_APP_ID);
    console.log(ngxEnv.production);
  }
}

setNgxEnv(environment, options) options parameters:

Option Detail
origin value provided here is matched with current window origin. If it does not match ngxEnv.<ENV_VAR> will return undefined for all environment variables.
envVarName value provided here will rename ngxEnv. Environment variable can be used as <envVarName>.<ENV_VAR>.Warning: do not use any reserved keyword or any window object property. Do NOT forgot to change your declaration statement in src/typings.d.ts.

Author

Saurav Singh

LICENSE

MIT

Package Sidebar

Install

npm i ngx-environment-variable

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

18.4 kB

Total Files

20

Last publish

Collaborators

  • sauravgaursmith