How to check if Angular application running in Production or Development mode

You can use this function isDevMode

import { isDevMode } from '@angular/core';

...
export class AppComponent { 
  constructor() {
    console.log(isDevMode());
  }
}

One note: be carefull with this function

if(isDevMode()) {
  enableProdMode();
}

You will get

Error: Cannot enable prod mode after platform setup

  • https://github.com/angular/angular/blob/2.0.0/modules/%40angular/core/src/application_ref.ts#L58

Other options

environment variable

import { environment } from 'src/environments/environment';

if (environment.production) {
  //
}

injected by webpack process.env.NODE_ENV variable

declare let process: any;
const env = process.env.NODE_ENV;

if (env  === 'production') {
  //
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)