How to detect dev vs production
See original GitHub issueForgive 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:
- Created 7 years ago
- Reactions:2
- Comments:14 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I suggest to use NODE_ENV.
In case someone (else) comes here through Google, check this example…