-1

When running my project locally with ng serve, I want to execute some different code blocks than when I run the prject on my server (we have a DEV, STAGING and a PROD environment on the server.) So I need to check if I'm currently running on

  • LOCAL,

  • or on DEV, STAGING, PROD.

Here How to check if Angular application running in Production or Development mode are answers to how to check, if the project is running in DEV or PROD Mode (e.g. with isDevMode). So it would only help if I needed to check if I'm running on

  • LOCAL, DEV, STAGING,

  • or on PROD.

Boommeister
  • 1,591
  • 2
  • 15
  • 54

2 Answers2

1

I solved it by adding a name attribute in my environemt.ts files and then checking for this attribute in the code:

if (environment.name === 'LOCAL') {
  console.log('%c LOCAL MODE', 'color: orange;')
} else {
  ... not local
}
Boommeister
  • 1,591
  • 2
  • 15
  • 54
-1

If you're using Node.js, you can may use the environment-variables. In your case its:

if(process.env.NODE_ENV == "development" )

further examples

Abilogos
  • 4,777
  • 2
  • 19
  • 39
Paul Werner
  • 87
  • 1
  • 8