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
Server may need to use the variables on the client so it's there for convenience
I see. So for server we should use import { env } from "../../../env/server.mjs"
Yes
But for client, should we use import { env } from "../../../env/client.mjs" or process.env...
Yes
Yes meaning either is fine?
Well it's better to use the file since you know they'll be typed and accurate
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"?