Home  >  Article  >  Web Front-end  >  Stop Using dotenv file

Stop Using dotenv file

WBOY
WBOYOriginal
2024-08-22 19:02:19783browse

Whenever it comes to securing the API keys or something that we don't want to be exposed to the public for our Open Source Project, we always tend towards the .env file, and every week, 29k+ developers download a trendy package, dotenv.

Stop Using dotenv file

Why is the filename only .env?

It's a myth, that the filename can only start with .env. You can name it anything and it will still be working fine with node.js.

For example, this is my folder structure to test this feature, and as you can see, instead of .env, I added my name as a filename.

Stop Using dotenv file

This file contains a PORT, which I want to print in my main file

Stop Using dotenv file

Stop Using dotenv file

And, as you can see, the PORT is being printed in the console. Stop Using dotenv file

Why we should be using dot( . ), in front of the environment file ?

When it comes to environment files, it's considered good to use a dot ( . ), in front of the filename, because adding a dot in front of any file name, makes it a hidden file or folder.

That's why there are multiple folders in your OS, that are hidden and can only be accessed via CLI, For example, .ssh, .github, .vscode, etc.

How to access the environment file without using dotenv?

Instead of using dotenv to read environment files, you can use the node.js inbuilt method to read them, which is

node --env-file=.env app.js

Here, instead of using .env as a file name, you can use any file name that is in your root folder.

Stop Using dotenv file

The above is the detailed content of Stop Using dotenv file. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn