Comments (9)
we removed the feature of environment specific .env files in 1.0
from dotenv.
Indeed. Optionally you can now use the config method to point to them. But we recommend the best practice of a single .env local to your environment.
On Fri, Mar 20, 2015 at 9:09 AM, Jacob Lowe [email protected]
wrote:
we removed the feature of environment specific .env files in 1.0
Reply to this email directly or view it on GitHub:
#60 (comment)
from dotenv.
How do you have a single .env if you have a development environment and testing environment? Just trying to figure out best practice.
from dotenv.
@drewhamlett this is easiest if you keep .env out of source control. You'll want to create a .env for each environment (development and testing in your example). If any values are the same across environments, it's not really an environment variable ๐ธ
development environment:
NODE_ENV=development
PG_URL=postgres://wtf:wtf@development:1234/development
testing environment:
NODE_ENV=testing
PG_URL=postgres://blah@localhost:5432/cool
Happy to provide more real-world examples if that would be helpful
from dotenv.
The ship may have sailed, but I can offer another real-life example of when environment-specific files can be helpful: local integration tests.
For our integration tests, we delete our database and recreate it so that it is pristine between tests. The tests run against a clean database and are responsible for setting up the data they need. Instead of blowing away all of the data in the local databases we use during development, we have a separate local database for testing and reference its URL by using a .env.test
file.
Sadly, when I upgraded dotenv
on Monday and ran npm test
everything worked, but the data that I had set up for use when doing development work and manual validating of features was all gone. My two options now are to not upgrade dotenv
or to figure out a new way of managing the testing database.
from dotenv.
@jeffkole you can still use your .env.test
file by loading it first. See #63 for example.
If only your database names follow a convention like app
and app_test
, you could have your integration tests prepare them without needing an additional .env.test
file (assuming database name is the only difference)
process.env.db_name = process.env.db_name + '_test'
You could also look to run your app in a container to isolate environments. Hope this helps your situation.
from dotenv.
I can't get dotenv to work either. I have one .env file and a config.js that is populated with process.env
values. It seems to be a race condition as my config file is never populated.
Express app: /bin/www. First line.
var dotenv = require('dotenv').load();
var config = require('../config');
console.log(config);
...
Console
dbName: undefined,
host: undefined,
URL: undefined,
user: undefined,
account: undefined,
...
from dotenv.
@kevinSuttle I don't think this is the same issue, please open up a separate issue and please give more insight on how config is being written. Chances are if you log out process.env and the dotenv
variables are there then there is not much this library can fix.
from dotenv.
@kevinSuttle That does look like a separate issue. Can you open in a separate issue, and share your config.json
file code. We'll take a look from there and help you debug.
Closing this issue.
from dotenv.
Related Issues (20)
- only the page with require("dotenv").config is seeing values HOT 2
- NodeJS 18 native feature caveats and `dotenvx` HOT 5
- Archive repo HOT 3
- Bug: `_parseVault()` doesnโt respect `processEnv` option. HOT 3
- Can we throw or stop execution through .env? HOT 3
- Readme links to nonexisting example page HOT 2
- override system variables HOT 2
- Cannot find module 'node:url' or its corresponding type declarations HOT 4
- In ES6 DOTENV enviroment not getting HOT 2
- Use of dotenv in a cron job with ES6 modules HOT 2
- Another issue asking about multiple env files HOT 6
- Links in examples section on NPM package page are broken HOT 1
- DotenvPopulateOutput typing is incorrect HOT 1
- Request for help! HOT 3
- Possible regression: `USERNAME` in .env file does not update process.env on Windows HOT 9
- Using an array for config.path does not work HOT 1
- Crypto HOT 1
- Troubleshooting dotenv Preloading in GitHub Actions HOT 3
- Multiple paths in config: README incorrect? HOT 8
- Getting error while reinstalling the dotenv (updating to `16.4.4` should fix. apologies for the bad patch release of `16.4.3` everyone) HOT 28
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 dotenv.