Next.js Discord

Discord Forum

Env var in app/api/something/route.ts

Answered
Mossyrose gall wasp posted this in #help-forum
Open in Discord
Mossyrose gall waspOP
I have a route handler that works locally when using environment variables but when deployed to Vercel, the API isn't working because of the env var's. When I remove them, the API works fine.

Can env var's be used in a route handler? If so, do they need to be loaded in a special way?

Currently I am doing process.env.VARIABLE_NAME.
Answered by Mossyrose gall wasp
So I assume the answer is yes and process.env.VARIBLE_NAME is the correct way, ok, will keep on trying. Thanks.
View full answer

6 Replies

Mossyrose gall waspOP
Yep 🙂
and checked the box for type of deployment?
Mossyrose gall waspOP
As in production, preview? If so, yes
I'd suggest to redeploy your project once
Mossyrose gall waspOP
So I assume the answer is yes and process.env.VARIBLE_NAME is the correct way, ok, will keep on trying. Thanks.
Answer