Giter VIP home page Giter VIP logo

custom-env's People

Contributors

amcereijo avatar coogie avatar ericrallen avatar erisanolasheni avatar fgriberi avatar gitter-badger avatar neo773 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

custom-env's Issues

An option to not output warnings to the console

Hi,

I'm using custom-env version 2.0.1.

When running tests I get console warnings like:

console.warn
  No env file present for the current environment:  test 
   Falling back to .env config

This is because I just have a .env file, and no explicit .env.test version (and no real desire to just duplicate these values in two places!)

Is there a way to hide these warnings?

i.e. like this maybe

require('custom-env').quiet().env();

or maybe as a configuration option (though, without named options this gets ugly pretty quickly!)

require(`custom-env`).env(true, null, true, true); // 4th argument would be quiet or not.

Another option might be to somehow provide a custom logger which would default to console?

require('custom-env').logger(MyLogger).env();

Happy to go with whichever option fits your style, and I can have a poke at a pull request if you like?

after goes to 1.0.2, my configuration not work anymore

After goes to 1.0.2 version, the property value like 'abc$2011' can be loaded correctly, the value been loaded will only have "abc". Is this supposed to work in this way?

At least at 1.0.0, ther is no such kind of issue.

Dynamic environment

Hello,

I am having issues loading the .env file based on NODE_ENV
require('custom-env').env(true) is not working, neither require('custom-env').env() - the env() function requires certain arguments.

Thoughts?

Characters after $ in the variable value are getting lost

Inside the file:
variable=abc$123

getting output as abc and not abc$123

Tried to keep the value in single quotes.
Tried to use \ before $ as to escape the special character
Tried combination of both
Tried abc$\123, it gives output as abc123, but not abc$123

Example how to use this with dotenvExpand?

My current setup:

import dotenv from 'dotenv'
import dotenvExpand from 'dotenv-expand'

dotenvExpand(dotenv.config())

console.info('APP_ENV:', process.env.APP_ENV)

Trying to introduce custom-env and load .env.{stage_name}

import dotenv from 'dotenv'
import dotenvExpand from 'dotenv-expand'

const customEnv = require('custom-env').env('prod')

dotenvExpand(customEnv.config())
console.info('APP_ENV:', process.env.APP_ENV)

It will print the .env variable, not the .env.prod variable.

P.S. I can't seem to find how to use import rather than require.

Handle NODE_ENV under npm on Windows

I noticed during development, custom-env was always falling back to the default .env file. It seems as though there's some edge cases when using under Windows.

When setting NODE_ENV and running through npm, it appears that NODE_ENV can get a whitespace character appended under certain conditions. This was causing custom-env to fail finding the file because https://github.com/erisanolasheni/custom-env/blob/master/lib/main.js#L85 was failing.

This can be replicated with the following:

package.json

"scripts": {
  "start": "set NODE_ENV=development && node"
}

Terminal

$ npm start
> console.log(`|${process.env.NODE_ENV}|`)
|development |

Inconsistency in selecting .env file and undocumented behavior for 'dev'

After struggling with figuring out why my environment variables weren't present for NODE_ENV=dev, I looked into the code and learned the following:

  • Despite explicitly setting NODE_ENV=dev, due to the special treatment of that environment specifier it loads .env first if it is present. (I had both .env and .env.dev.) I think this would be unexpected in most cases - more specification should usually take precedent over less specification.

  • The documentation states a few times that if the environment is not specified, it is assumed to be development. This is not strictly true - if no environment is specified it attempts to load .env. (Full stop.) It doesn't necessarily imply anything about the runtime environment, just which file it will look for.

IMO it would be better to make the filename lookup consistent for all environment specifiers, so there are no 'surprise' special cases. Specifically, if the environment is 'dev', then .env.dev is loaded if present. A nice fallback might be to look for .env as a fallback for both the case where the environment is not specified (as currently) and for the case where the environment-specific file is not present (e.g. if env=dev and .env.dev is not available, it tries to load .env as a second priority).

instanceof Array incorrectly returns false

main.js: 76
if (filesInDir instanceof Array && filesInDir.length > 0)

instanceof returns false even if filesInDir is actually a nonempty array. Use instead:
if (Array.isArray(filesInDir) && filesInDir.length > 0)

This works correctly.

Duplicate envname

Having duplicate envname error. please find below line

node_modules/custom-env/lib/main.js: Duplicate declaration "envname"
  59 |         // Check if dir exists and its a directory
  60 |         var dir = typeof (dir) == 'string' ? dir : process.cwd()
> 61 |         var envname = typeof (envname) == 'string' ? envname : envname === true && process.env.NODE_ENV ? process.env.NODE_ENV : false
     |             ^
  62 | 
  63 | 
  64 |         var dirIsDirectory = fs.lstatSync(dir).isDirectory()

Example on Loading from the current environment

Hello thanks for this but I am a bit confused on how to make the env automatically change if in production or development, i don't want to always be changing the value.

How to do so ?
require("custom-env").env("development"); // change based on current environment as cant do an if check since its at the top of file.

Thanks.

custom-env is not recognizing second argument

I have my .env.prod file a directory that is different from the script where I call the following

I'm calling the code below in /var/www/pm/bin/worker.js

require("custom-env").env("prod", '/var/www/pm/');

I have the .env.prod script in /var/www/pm/.env.prod

I tried to tell custom-env that the .env.prod file is in /var/www/pm but it still gives me an error

No env file present for the current environment: staging

I'm I doing something wrong?

Consider adding TypeScript type definitions

For those of us using TypeScript, it would be useful to have TypeScript typings for this library.

Thank you for creating this library, as it does solve the issue of managing multiple environment configurations very elegantly.

Consider adding support for dotenv-expand

dotenv-expand allows developers to reference process.env variables inside their .env files.

For example:

IP=127.0.0.1
PORT=1234
APP_URL=http://${IP}:${PORT}

Using the above example .env file, process.env.APP_URL would be http://127.0.0.1:1234.

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.