question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to detect dev vs production

See original GitHub issue

Forgive me if this is an extremely basic question, but I’m struggling to figure out how to determine if my code is running in dev or production.

I tried adding env vars to my scripts in package.json:

  "scripts": {
    "dev": "ENV=dev next",
    "build": "ENV=production next build",
    "start": "ENV=production next start"
  }

though I don’t know how to access these variables. I tried:

const ENV = 'undefined' !== typeof window ? window.ENV : process.ENV

but this didn’t seem to work. These variables don’t show up in window object from browser.

From my understanding, window is available on client and process is available on server, but I’m not sure how to set a var on them, or access that var appropriately. Alternatively, is there an existing variable that indicates production vs dev mode?

Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

17reactions
seduboiscommented, Mar 7, 2017

I suggest to use NODE_ENV.

16reactions
malixsyscommented, Aug 24, 2019

In case someone (else) comes here through Google, check this example

Read more comments on GitHub >

github_iconTop Results From Across the Web

Easiest way to detect Production or Dev environment in NextJs?
I want to basically detect whether the running environment is dev or production in Nextjs. Is there any straight forward way of doing...
Read more >
How to detect dev vs production #1365 - vercel/next.js - GitHub
Forgive me if this is an extremely basic question, but I'm struggling to figure out how to determine if my code is running...
Read more >
Node.js, the difference between development and production
You can signal Node.js that you are running in production by setting the NODE_ENV=production environment variable. This is usually done by executing the...
Read more >
Difference Between Development, Stage, And Production
I know some companies name the environments differently, so Stage is similar to production and QA is the unstable env. Some others use...
Read more >
How to detect whether in production or development ... - MSDN
The reason I am asking is that for some actions I need to construct fully qualified URLs. In the development environment these URLs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found