Questions tagged [dotenv]

This tag is for questions about the Dotenv Node.js module. For PHP, see the `phpdotenv` tag; for ruby, see the `ruby-dotenv` tag.

Dotenv is a zero-dependency Node.js module that loads environment variables from a .env file into process.env. Storing configuration in the environment separate from code is based on The Twelve-Factor App methodology.

Find NPM package here for documentaion.

Other language implementations

821 questions
7
votes
2 answers

Cypress load environment variables in custom commands

I'm building a Next.js app and write my tests using Cypress. I configure the environment variables using a .env.local file locally. In the CI pipeline, they are defined normally. I'm trying to write a custom command in Cypress that encrypts a…
J. Hesters
  • 13,117
  • 31
  • 133
  • 249
7
votes
1 answer

environment variables not updating

I am using the dotenv package. I had a key that I had saved in my .env file but I updated it to a new key, but my script still outputs the old key. I have the ".env" file in the root directory. I thought that by using load_dotenv() that it's taking…
hope288
  • 725
  • 12
  • 23
7
votes
1 answer

Laravel Environment Variables(without default value passed in method) not working inside Artisan Command file

I am using Laravel 6.x for client's project wherein I have built an API in the Artisan Command for syncing data. Now client wants the configuration to be discreet, out of main source code and without any fallback values as possible. That means I…
Vicky Dev
  • 1,893
  • 2
  • 27
  • 62
7
votes
5 answers

Can't find dotenv environment variables from cron job

I am running a python script from a python library which loads some environment variables from a .env file in the root of the library using dotenv. This works from the command line, but when I try to run as a cronjob using the following: * * * * *…
Archie
  • 333
  • 2
  • 9
7
votes
2 answers

.env with debugging breakpoint using vscode and dotenv npm

I'm using a nodejs server side api, setting up environment variables with dotenv npm package, and running the code from npm scripts in package.json as below: "scripts": { "local": "cross-env NODE_ENV=local nodemon ./bin/www" } What I need is…
R.G.Krish
  • 487
  • 5
  • 22
6
votes
4 answers

How to I access my .env variables from a vitest test?

I am trying to migrate my tests from jest to vitest. I have a test suite that uses the dotenv package to pull in my .env variables. I have this in my test suite beforeAll(async () => { vi.clearAllMocks(); cleanUpMetadata(); …
Bebet
  • 199
  • 2
  • 12
6
votes
1 answer

How to use multiple .env files in Prisma?

I am working on a nestjs project using Prisma, and I want to use multiple .env files with Prisma. I follow the guide here. According to the guide, I add: "migratetest:mysql": "dotenv -e .env.test -- npx prisma migrate dev", "migratedev:mysql":…
Erika
  • 453
  • 8
  • 23
6
votes
1 answer

My React app is using values from the .env file instead of the .env.local file

The dotenv module should be prioritizing my .env.local file over my .env file, but it's not. When I have REACT_APP_API_BASE set in both files, the app always uses the value in .env. It only uses the value in .env.local if I delete the matching…
carpiediem
  • 1,918
  • 22
  • 41
6
votes
1 answer

How to properly manage .env files in a microservices architecture

I have been working for some time on a project with a microservices architecture where each service has its own environment variables which are handled with a .env file for each service/repository. A great part of these variables are related to…
reymon359
  • 1,240
  • 2
  • 11
  • 34
6
votes
0 answers

Dynamic proxy setting in package.json

I am learning how to use express together with a create-react-app. One of the internal wiring would be to set a proxy keyword in the package.json for the client side. However, I am interested to know how to dynamically inject a value into that…
AKJ
  • 749
  • 6
  • 29
6
votes
2 answers

Should I commit an empty .env file?

I have a .env file storing my database information, and I'm about to publish my project on GitHub. So, my question is, should I commit an empty .env file with the keys that I need, but without the values so other people can understand how to fulfill…
DoceAzedo
  • 342
  • 4
  • 12
6
votes
3 answers

Fail Gatsby build if environment variable missing

I have experimented with adding environment variables to my Gatsby project using .env.development and .env.production files and it's working great. I would like to have my builds fail if one of the environment variables is missing, however I can't…
harveyives
  • 105
  • 8
6
votes
1 answer

NestJS .env file doesn't get built

I'm using dotenv v8.2.0 in my NestJS project, and it has always worked in my production environment. I cloned the project on my new pc, made a .env file with the right variables in the root folder, but the .env file now doesn't get built into the…
Jasper Rosiers
  • 277
  • 2
  • 5
  • 16
6
votes
1 answer

NestJS env variable undefined

I'm trying to set configuration variables on my project using the official documentation. I added the following line to my app.module.ts imports: ConfigModule.forRoot({ isGlobal: true }), I created a .env file at the root of my project with the…
Platus
  • 1,753
  • 8
  • 25
  • 51
6
votes
3 answers

How to inject dotenv variables without REACT_APP prefix in create-react-app?

I have a project to migrate from legacy React app to standard create-react-app one (not ejected). In legacy project, it manually loads .env files with dotenv and dotenv-expand and injects through webpack DefinePlugin. create-react-app intuitively…
Mike
  • 313
  • 4
  • 15