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

maxbellec picture maxbellec · Sep 16, 2016 · Viewed 72.5k times · Source

This seems an easy one, but I couldn't find any solution.

So, how do I check if my app is running in production mode or dev mode?

Answer

yurzui picture yurzui · Sep 16, 2016

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

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') {
  //
}