Next.js Discord

Discord Forum

how to display different data based on vercel env

Unanswered
Southeastern blueberry bee posted this in #help-forum
Open in Discord
Southeastern blueberry beeOP
Using Vercel with two environments, main for production and dev for preview, how can I show dynamic data based on these two environments?

3 Replies

@Southeastern blueberry bee Using Vercel with two environments, main for production and dev for preview, how can I show dynamic data based on these two environments?
you can access env variables via process.env.variablename. And after you accessed it, you can make conditional statements with it. For example:
if(process.env.variablename === "production")
  // do stuff

If you just want to get the current env (dev, prod, ...) you can access the env variable NODE_ENV. That will give you a string of the current enviorement (test, production or development)
@Southeastern blueberry bee solved?
@B33fb0n3 <@421263317609218048> solved?
Southeastern blueberry beeOP
This worked in nextjs and vercel
process.env.NEXT_PUBLIC_VERCEL_ENV

Thanks for your help & time