Next.js Discord

Discord Forum

[Bug?] .env.local variables can not be accessed pages/api/<file>

Answered
American black bear posted this in #help-forum
Open in Discord
American black bearOP
According to docs, .env.local variables should be accesible within api directory to make requests to hide secrets. If i try to access the varibales with proccess.env.<NAME> I get undefined values.

in pages/api/file.ts
console.log(process.env.TWITCH_ID, ' ', process.env.TWITCH_SECRET);
=> Undefined Undefined

Any help appriciated since I need to use API routes to hide API secrets.
Answered by American black bear
seems to be bugged. If I use .env it works on the server side. Docs statel clearly that .env.local should be used AND that .env* should also work °_°
View full answer

5 Replies

American black bearOP
seems to be bugged. If I use .env it works on the server side. Docs statel clearly that .env.local should be used AND that .env* should also work °_°
Answer
sth with your file paths I guess

if you're using the app directory, the path should be app/api/posts/route.ts
American black bearOP
nah, it's just bugged
switched from .env.local to .env and it works