Env variable (I have read the t3 docs and it's still unclear to me)

I'm using import { env } from "../../../env/server.mjs"; for server environment variables. Should I use import { env } from "../../../env/client.mjs"; or process.env.NEXT_PUBLIC_MY_CLIENT_ENV_VAR for client side env variables? And why is it that in server.mjs we export the client side env data? export const env = { ..._serverEnv.data, ...clientEnv };
8 Replies
Pod
Pod3y ago
Server may need to use the variables on the client so it's there for convenience
shikishikichangchang
I see. So for server we should use import { env } from "../../../env/server.mjs"
Pod
Pod3y ago
Yes
shikishikichangchang
But for client, should we use import { env } from "../../../env/client.mjs" or process.env...
Pod
Pod3y ago
Yes
shikishikichangchang
Yes meaning either is fine?
Pod
Pod3y ago
Well it's better to use the file since you know they'll be typed and accurate
shikishikichangchang
ok thanks Why is it then in this file: src/utils/trpc.ts, we need to use process.env and cant do import { env } from "../../../env/server.mjs"?
Want results from more Discord servers?
Add your server