Next.js Discord

Discord Forum

Process env with Next.JS

Unanswered
Lionhead posted this in #help-forum
Open in Discord
LionheadOP
Hi there 👋
I was wondering, why process.env dosn’t work with javascript?
I can give github repo if needed.
Thanks in advance

5 Replies

LionheadOP
alr,

if (process.env.NODE_ENV !== 'production') globalThis.prismaGlobal = prisma

for example sth like that
and i got problem, that process env is not defined
only when using java script
but when typescript, i dont have that problem
Burmese
on the server process.env exists, but not on the client/browser. On the client, only env vars prefixed with NEXT_PUBLIC_ are available, and they are actually bundled into the code. If you want to use an env switch on the client you could add your own, something like NEXT_PUBLIC_APP_ENV and set different values in .env.* files...

I also just released a new open-source tool to help with env vars in next - https://dmno.dev/blog/dmno-nextjs-launch/ With this tool you can set vars to be marked as sensitive or not (should not be exposed to client), and dynamic or not (bundled)

Would love for you to try it out and hear what you think!