Next.js Discord

Discord Forum

Unable to use ENV locally

Answered
Caya posted this in #help-forum
Open in Discord
So i want to use some API which have some key so before implement it directly i wanted to use env for testing cuz i never used vercel's env before so i have a key and value in .env.local folder NEXT_PUBLIC_TESTING_VERCEL_ENV="testing" but when i try to console.log it in my project it gives me value as UNDEFINED so can someone help me with this
Answered by Toyger
should work.
did you try to restart dev server?
can you try to put some different NEXT_PUBLIC_ variable into .env file, and console.log it, to understand will it work at least somehow.
View full answer

7 Replies

Toyger
.env.local folder
folder? it should be file

can you also show code how you access it for console.log
@Toyger > .env.local folder folder? it should be file can you also show code how you access it for console.log
yeap its a file in root dir

export const Projects = () => {
  console.log(process.env.NEXT_PUBLIC_TESTING_VERCEL_ENV);
  return (
// rest of the code
\
@Caya yeap its a file in root dir js export const Projects = () => { console.log(process.env.NEXT_PUBLIC_TESTING_VERCEL_ENV); return ( // rest of the code \
Toyger
should work.
did you try to restart dev server?
can you try to put some different NEXT_PUBLIC_ variable into .env file, and console.log it, to understand will it work at least somehow.
Answer
@Toyger should work. did you try to restart dev server? can you try to put some different `NEXT_PUBLIC_` variable into `.env` file, and console.log it, to understand will it work at least somehow.
nope i haven't restated the dev server let me do that as well as let me try to console.log other variable too
@Toyger should work. did you try to restart dev server? can you try to put some different `NEXT_PUBLIC_` variable into `.env` file, and console.log it, to understand will it work at least somehow.
Hey thanks it worked i just restated the dev server and it worked lol

btw its consolelog that variable twice you know ehy?