Next.js Discord

Discord Forum

.env.local

Answered
Polish Lowland Sheepdog posted this in #help-forum
Open in Discord
Polish Lowland SheepdogOP
How to create .env.local file in Next.js14+ app. Lee vid "Introduction to Next.js and React" on YouTube at 34:33 Lee creates .env.local file with touch command that he also says works on Mac computers only. How do I create .env.local file on Windows computer? There is no explanation how to create this file in Next.js documentation either. Cheers
Answered by Anay-208
@Polish Lowland Sheepdog
View full answer

43 Replies

Asian paper wasp
He said Mac only because touch is a Linux (Mac is built on top of Linux, kind of) command used for creating an empty file.

You just use whatever way you already know to create the same file
Polish Lowland SheepdogOP
I do not know how to create .env.local file. This is what I am asking here.
Asian paper wasp
You know how to create an ordinary, empty file on windows right?
Polish Lowland SheepdogOP
I thought there is more to this in .inv.local case. Like I need Next app to do it. Something with path maybe. Why Lee uses touch command and not creating it manually ?
Asian paper wasp
File and folder names that start with a dot are typically considered hidden files by the OS (Windows in your case).
As for using touch, it is properly just because Lee find it more convient
That's literally nothing special about it. That's just a way to create a file
Polish Lowland SheepdogOP
There is 41 second video "How to use a .env file to load environment variables in a dev container" on YouTube. Guy makes devcontainer.env and also devcontainer.json, where he adds some mods. Do i need to do .json also and add those mods.
Polish Lowland SheepdogOP
Thanks Mwskwong . I will keep pushing again tomorrow morning. Too stressed up now. Did not get to anywhere today. Trying to log into Discord took an effort ...
touch .env.local
@Polish Lowland Sheepdog I've a question, how did you make page.tsx?
wrong ping
Polish Lowland SheepdogOP
create-next-app@latest
@Polish Lowland Sheepdog create-next-app@latest
no, like if you try to create a route like /contact
Polish Lowland SheepdogOP
Fallowing Lee's YouTube video
use the same step to create .env.local
right click at project dir, create .env.local
Polish Lowland SheepdogOP
Yes I know how to add ordinary files in vscode/next
Thought .env is special
Asian paper wasp
.env.local is LITERALLY an ordinary file...
Polish Lowland SheepdogOP
That i need Next to do this
Polish Lowland SheepdogOP
Thought Next will do some behind the scenes stuf... with path or smth.
Asian paper wasp
You use the same way of creating page.tsx to create .env.local period
npx create-next-app@latest next-app
cd next-app 
touch .env.local
code .env.local
Polish Lowland SheepdogOP
Cheers
Asian paper wasp
No offense, but maybe Next.js is too early for you.
.env* has nothing to do with Next.js alone, it is a common file naming convention for specifying environment variables
Which code editor are you using, I'll share a video recording
Polish Lowland SheepdogOP
First time in Discord too...thanks for so pleasant experience.
vscode
I'll send you a video recording in a min
Polish Lowland SheepdogOP
Back in a bit, cigarette
@Polish Lowland Sheepdog
Answer
to open that dropdown, I right clicked
and after typing done in the comment, I deleted .env.local to show you again
Polish Lowland SheepdogOP
Yes see I need to do more than just create .env. that's why I was looking to create .env file like Lee did it, with command.
It's all clear now. Thanks for 5 star help. You are HERO
ln Lee's video there is no env.json file created though ...
And inv.local file is created to public folder, thais can't be right ...
right click at the empty space where I created, or the nextjs folder