Next.js Discord

Discord Forum

.env.local file returning undefined

Unanswered
Chinese Alligator posted this in #help-forum
Open in Discord
Chinese AlligatorOP
This is my .env.local file :
DISCORD_WEBHOOK_URL="https://discord.com/api"


But when i do
      console.log("Webhook URL:", process.env.DISCORD_WEBHOOK_URL);


It returns undefined
My file extension is .js

8 Replies

Toyger
how are you using it? it can be used only in
Next.js data fetching methods and API routes.

if you want to use it in client side, you need to have prefix NEXT_PUBLIC_ for your env variables
@Chinese Alligator I want to use it in server side
Toyger
ok, where exactly, in api route/route handler/server action/getstaticprops/etc...?
@Toyger ok, where exactly, in api route/route handler/server action/getstaticprops/etc...?
Chinese AlligatorOP
app/_actions/discord.js
Um
I think it got fixed
With using "use server" at the first