I am trying to read the environment variable property using
process.env['KEY_TO_READ']
This KEY_TO_READ i am setting up in the environment variable. But, its not taking up at compile time only i am getting the below error:
Cannot find name 'process'.
Somewhere i read like in angular app we cannot use process because it will be defined at runtime. Is it correct ? If yes then can anyone suggest how i can achieve this . I don't want to use angular-cli environment file options.
Angular provides build-in support to configure and manage Environment Variables. It keeps the environment configuration under the folder src/environments folder.
An Angular Application Environment is JSON configuration information that tells the build system which files to change when you use ng build and ng serve . Let's say you have a back end REST API deployed on a server that provides services to your Angular application.
A project's src/environments/ folder contains the base configuration file, environment.ts , which provides a default environment. You can add override defaults for additional environments, such as production and staging, in target-specific configuration files.
You ll have your environment file as,
environment.ts:
export const environment = {
production: false,
envName: 'dev',
KEY_TO_READ: 'test'
};
It is exported so you can import it:
import { environment } from './environment';
export class MyappAppComponent {
title = 'myapp works!';
KEY_TO_READ = environment.KEY_TO_READ;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With