#how should environment variables be accessed from server endpoints?

2 messages · Page 1 of 1 (latest)

plucky kiln
#

The docs mention that a server endpoint can use environment variables, but doesn't say how. I found that I was able to get variables from import.meta.env when using yarn dev, but when I deployed to Netlify, the variables weren't found. When I switched to process.env, it worked on Netlify, but not in yarn dev.

Is there a way to use the same code in both environments?

pastel ridge
#

I'd use process.env as a fallback value

const secret = import.meta.env.SECRET || process.env.SECRET