Comments (3)
Thanks for the information for those users.
For what it's worth, some advice: if you want to use these tools properly, don't import dotenv
. I'd personally consider it a stark anti-pattern that will cause you problems in the long run, anyway. Use the CLI utility to prefix anything you want to have load the environment variables from. It would (well, should) sidestep any of the nonsense surrounding .enable()
/.disable()
behavior.
Just my $0.02. Hardcoding anything about the environment into your source directly rarely works out for you in the long run.
EDIT: Huh. Doesn't seem that there's a CLI like I thought. This utility would be... well, rather trivial to wrap for any process that needs it, not just Node. Anyway, node -r dotenv/config ...
should work, according to their docs. Stick it into your start
script if you don't want to type it each time.
from debug.
I'm going to close this since it's not really an 'open' issue but if I see more issues filed w.r.t. dotenv in the future I'll pin this for visibility.
from debug.
Just my $0.02. Hardcoding anything about the environment into your source directly rarely works out for you in the long run.
In my case, I was trying to emulate the behaviour from the create-react-app
, which I believe was based on the behaviour of the Ruby gem1 that existed before the JS dotenv project came to exist.
It worked by trying to load different .env
files according to the detected environment.
So in my example, the // Do dotenv things
section would rather look something like this:
import { existsSync } from 'node:fs'
import { cwd } from 'node:process'
import path from 'node:path'
...
// Do dotenv things
const nodeEnv = process.env.NODE_ENV ?? 'development'
const envFiles = [`.env.${nodeEnv}.local`, '.env.local', `.env.${nodeEnv}`, '.env']
.filter((envFile) => existsSync(path.resolve(path.join(cwd(),envFile))))
for(const envFile of envFiles) {
dotenv.config({ path: envFile })
}
As an example scenario, it would allow me to easily switch or (selectively) override (debug
) settings.
Which could handy in case you have a generic .env file included in a Docker build and want to override only particular variables in a specific environment, or want or need to tune them. This is a safe(r) escape hatch without having to manage full environment variables and the potential discrepancies this might bring. (Which is obviously why dotenv-vault
came to rise.)
Though, you are absolutely correct, this would ideally be implemented using a preload script that provides this functionality.
from debug.
Related Issues (20)
- INEFFICIENT REGULAR EXPRESSION COMPLEXITY IN DEBUG HOT 1
- [Question] How do I enable millisecond diff?
- Issue in Next.js HOT 5
- Redirect logs to file doesnt capture time HOT 2
- Different formatting for namespaces on TTY and files
- Specify peer dependency version
- Specify namespace with url in ESM HOT 5
- npm ERR! code ENOENT npm ERR! syscall open npm ERR! path C:\Users\sahar\Desktop\myCode\jonas_React_course\React_Jonas_20_10_2023\project_pizza-menu\package.json npm ERR! errno -4058 npm ERR! enoent Could not read package.json: Error: ENOENT: no such file or directory, open 'C:\Users\sahar\Desktop\myCode\jonas_React_course\React_Jonas_20_10_2023\project_pizza-menu\package.json' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent HOT 1
- Debug mixed with console.log HOT 6
- Debug Checkmarx Vulnerability HOT 1
- Avoid throwing errors
- useColors return false after modify user-agent in tauri app HOT 1
- Colour lost when using Node native test running (Node 18+) HOT 2
- Alternate solution to CWE-1333 | Inefficient Regular Expression Complexity
- Display full error object all the time regardless of argument position
- DEBUG_HIDE_DATE doesn't exist / do anything
- Property 'type' does not exist on type 'Process'.
- How to set max array length (`maxArrayLength`)? HOT 1
- update colors for darkmode in devtools
- Allow choice between STDERR and STDOUT
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from debug.