Generating Automated Multiple Environment.ts In Angular Using .env And Node Js

Setting up Angular for Multiple Environment

  1. Fresh installation of angular. From terminal type in
ng new <projectName>

  1. Go to inside the project
cd projectName

  1. Generate environment files
ng generate environments

  1. This is the expected directory and files that will be generated
projectName/src/environments
environment.ts
environment.development.ts
environment.staging.ts

  1. For debugging, import the environment to app.component.ts
import { Component } from '@angular/core';
import { environment } from './../environments/environment';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor() {
    console.log(environment.production); // Logs false for development environment
  }

  title = 'app works!';
}

  1. Rename some of the files accroding to the needs of the project. Like for instance I renamed it to
projectName/src/environments
environment.ts
environment.staging.ts
environment.prod.ts