Code Monkey home page Code Monkey logo

Comments (9)

jcblw avatar jcblw commented on May 22, 2024 1

we removed the feature of environment specific .env files in 1.0

from dotenv.

motdotla avatar motdotla commented on May 22, 2024

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.

drewhamlett avatar drewhamlett commented on May 22, 2024

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.

maxbeatty avatar maxbeatty commented on May 22, 2024

@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.

jeffkole avatar jeffkole commented on May 22, 2024

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.

maxbeatty avatar maxbeatty commented on May 22, 2024

@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.

kevinSuttle avatar kevinSuttle commented on May 22, 2024

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.

jcblw avatar jcblw commented on May 22, 2024

@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.

motdotla avatar motdotla commented on May 22, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.