The dotenv error that will cost you an entire afternoon

Is your app ignoring changes in .env? Find out why dotenv does not overwrite variables and how to fix it in seconds. Save hours of frustration.

domingo, 5 de julio de 2026 • 2 min read • Q2BSTUDIO Team

How to prevent old environment variables from ruining your app

In software development, configuration management is a critical point that often leads to hard-to-track confusion. A recurring case occurs with libraries like dotenv, which by design do not overwrite environment variables already defined in the system. This behavior, although correct from the perspective of twelve-factor app best practices, can cause errors in development environments when an outdated variable remains stored in the shell or in startup files like .zshrc or .bashrc.

Let's imagine a typical scenario: a team works on custom applications that consume external services via API keys. When modifying the .env file with a new valid key, the application continues using the old one because the process has inherited an environment variable from the shell. This causes intermittent failures, such as quota or authentication errors, which are often mistakenly attributed to the network, the service provider, or even the server configuration. The key is understanding that dotenv prioritizes real environment variables over those in the local file, and that to force reading the .env in development, the override: true option is needed.

At Q2BSTUDIO, when developing custom software for companies in various sectors, we incorporate these considerations from the architecture. For example, when integrating artificial intelligence or AI agents into business processes, proper credential management is essential to avoid information leaks or unnecessary costs. Similarly, in cybersecurity and pentesting projects, controlling the origin of each environment variable prevents incorrect configurations from opening security gaps. Our team also deploys solutions on AWS and Azure cloud services, where environment variables are injected from managed services, and it is crucial that local developers respect that hierarchy.

To diagnose this problem, simply print the final value of the variable that the application is actually using. If it does not match what is expected, look for the source of the outdated value: it could be in an export in profile files, in a docker run -e, or in a CI secret. The most direct solution for development is to enable override: true in the dotenv call, but you can also choose to clean the shell manually if you prefer to keep the default behavior in production.

Beyond API keys, this same dynamic affects database configurations, business intelligence service endpoints, or connections to tools like Power BI. Therefore, we recommend our clients, when developing custom applications, establish a configuration strategy from the start, differentiating between environments and documenting dependencies. If you need support in creating AI for businesses or automating workflows, at Q2BSTUDIO we integrate these practices to ensure reliable and efficient deployments.

In summary, when an environment variable refuses to change, don't waste your afternoon looking at invoices or provider logs. Check what value your application process is reading. One line of debugging can save you hours. And if your team needs to strengthen its development processes or migrate to a more robust architecture, our custom software service is designed to avoid this kind of headache.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.