How to access ENV variables on client side with NextJS

Hello guys

We have some env variables setup in edg Environments | Edgio Documentation

We can access those at the build time. How can be get those env also at client side with NextJS? This is more of NextJS issue for sure :slight_smile:


How about edg env pull my-file.env?

I think that could work. In edgio console, defined env variable like this:


And then add to the build process, before running the actual build

edg env pull .env.production

As per Basic Features: Environment Variables | Next.js

I wonder if maybe just naming the variable and than running the build might work just like that

1 Like

If I understand the ask correctly, so long as the env vars are prefixed with NEXT_PUBLIC_, then you can use them on the client with process.env.NEXT_PUBLIC_XYZ.

Now if they are defined in Edgio console, you will need to do edg env pull ... as you referenced to bring them local for building/local dev.

1 Like