Code Monkey home page Code Monkey logo

Comments (10)

jcblw avatar jcblw commented on May 16, 2024 3

fixed with #62 release v.1.1.0

now you can silence dotenv

require('dotenv').config({silent: true})

from dotenv.

maxbeatty avatar maxbeatty commented on May 16, 2024

Let's put aside what's normal for production and what's not.

We do try/catch the error and politely console.log it as you've described because it's important to let someone know why dotenv may not be working. If we remove the log line, people are left to figure it out themselves (dig into source, add their own logs, etc.). We could add something like debug but then dotenv would no longer be dependency-free.

What's a solution that satisfies all of these concerns?

from dotenv.

jmike avatar jmike commented on May 16, 2024

Many thanks for the swift reply. I can only think of 2 possible solutions.

  1. Leave the code structure as-is; wrap the ENOENT error into something friendlier, e.g. ".env file not found". I would also suggest changing console.error to console.log, but that is debatable.
  2. Add a "verbose" or "debug" option to the #load method, set to true by default. That would give us the option to suppress errors by doing require('dotenv').load({verbose: false});

Hope that makes sense,

from dotenv.

jmike avatar jmike commented on May 16, 2024

Would a pull request help to get this going?

from dotenv.

jcblw avatar jcblw commented on May 16, 2024

@jmike those always seem to push things along faster πŸ˜„

from dotenv.

Neamar avatar Neamar commented on May 16, 2024

Since i have the same problem, i can volunteer for the PR if needed

from dotenv.

maxbeatty avatar maxbeatty commented on May 16, 2024

Took a stab at this in #62

from dotenv.

kachkaev avatar kachkaev commented on May 16, 2024

Hey guys,

It's great that there is a way to pass {silent: true} in the code to suppress an error. I'm wondering if something like that is also possible for babel users. Here is how I start my server:

#dev
nodemon src/ --exec \"node --require dotenv/config --require babel-register\"

#prod (not recommended; build instead and then run without babel)
babel-node --require dotenv/config --require babel-register src/

The reason for not using equire('dotenv').config({silent: true}) in src/index.js is that cannot be placed before import x from 'x', which may rely on process.env.*.

Any ideas?

from dotenv.

calebboyd avatar calebboyd commented on May 16, 2024

@kachkaev I think you can use dotenv_config_silent=true in node argv.

from dotenv.

kachkaev avatar kachkaev commented on May 16, 2024

@calebboyd thanks for the hint, I did not know this trick existed. Looks like in v3.0.0 this is no longer the case though. Errors are not shown by default unless you pass a verbose option.

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.