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
166
votes
28 answers

dotenv file is not loading environment variables

I have .env file at root folder file NODE_ENV=development NODE_HOST=localhost NODE_PORT=4000 NODE_HTTPS=false DB_HOST=localhost DB_USERNAME=user DB_PASSWORD=user And server.js file in the root/app/config/server.js folder. The first line of…
ANewGuyInTown
  • 5,957
  • 5
  • 33
  • 45
113
votes
8 answers

Toggle between multiple .env files like .env.development with node.js

I want to use separate .env files for each mode (development, production, etc...). When working on my vue.js projects, I can use files like .env.development or .env.production to get different values for the same env key. (example: in…
Jonas
  • 1,153
  • 2
  • 7
  • 7
87
votes
6 answers

NestJS - How to use .env variables in main app module file for database connection

I am working on my first NestJS application, which was working fine with hardcoded database connecting string in app.module.ts. But then as per our requirements, I had to pick the database config values from environment files. For that, I followed…
Mohit Bhardwaj
  • 9,650
  • 3
  • 37
  • 64
85
votes
5 answers

How to add comments to .env file?

I am using dotenv module to load environment variables from .env file. .env: # config DAILY_REPORT_SCHEDULE='*/1 * * * *' PORT=8080 NODE_ENV=development DOTENV_DEBUG=true #…
Lin Du
  • 88,126
  • 95
  • 281
  • 483
66
votes
12 answers

Environment variable with dotenv and TypeScript

I create this .env file: TYPE=xxx HOST=xxx, PORT=xxx, USERNAME=xxx, PASSWORD=xxx, DATABASE=xxx, in my file I use in this way: import * as dotenv from "dotenv"; dotenv.config(); export const typeOrmConfig: TypeOrmModuleOptions = { port:…
user13111868
42
votes
9 answers

Using private key in a .env file

I have a multiline private key in a gatsby .env file: GATSBY_GOOGLE_CLIENT_ID="12345" GATSBY_GOOGLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nflkdflkdf...\n-----END PRIVATE KEY-----" In my gatsby-config file I have: module.exports = { resolve:…
mckeever02
  • 641
  • 2
  • 7
  • 14
41
votes
5 answers

While running the script throws cannot find module 'dotenv'

While loading the .env file to pass env values to the getToken.js script in the cypress root folder throws Cannot find module 'dotenv'error. I have installed npm install dotenv. Could someone please advise what I am missing here ? .env file is…
soccerway
  • 10,371
  • 19
  • 67
  • 132
38
votes
8 answers

Module not found: Error: Can't resolve 'fs' in node_modules\dotenv\lib'

I'm trying to use dotenv with an angle, but when it comes to requiring dotenv require('dotenv').config() or const Dotenv = require('dotenv-webpack'); I get the following error: ERROR in ./node_modules/dotenv/lib/main.js Module not found:…
Jorge Nava
  • 495
  • 1
  • 5
  • 10
36
votes
5 answers

Is it secure way to store private values in .env file?

I'm trying to build a node.js server with express framework, and I want to store a private key for admin APIs in my server.I'm now using .env file to store those values, and in my routes, using that values by calling like process.env.ADMIN_KEY.…
hyojoon
  • 493
  • 1
  • 6
  • 17
35
votes
6 answers

How to fix "File '.../node_modules/dotenv/types' not found." error coming from jsconfig.json?

VSCode is showing errors for jsconfig.json: "File '.../node_modules/dotenv/types' not found." Appears to be looking for typescript definitions for dotenv, but I'm not using typescript or dotenv (other than in imported packages). And there is a…
Steve
  • 411
  • 1
  • 5
  • 5
30
votes
7 answers

Can't access gatsby environment variables on the client side

I set up .env file and gatsby-config.js as below. // .env.development GATSBY_API_URL=https://example.com/api // gatsby-config.js console.log(process.env) ... ... Although when to run gatsby develop, it shows all env vars including GATSBY_API_URL:…
kukrt
  • 2,117
  • 3
  • 21
  • 32
25
votes
7 answers

NestJs: Unable to read env variables in module files but able in service files?

I have an .env file at the root of my NestJs project with some env variables in it. The strange thing is that I am able to read the variables in service files but not in module files. So in a service file like users.service.ts, this…
Carven
  • 14,988
  • 29
  • 118
  • 161
24
votes
3 answers

How do you load environment variables from .env and .env.local with dotenv?

This might look like a newbie question, but I am unable to find the way to load environment variables from both .env and .env.local files in node with dotenv. Is it even possible? How do people load environment variables from both files nowadays if…
Adrian
  • 1,558
  • 1
  • 13
  • 31
24
votes
2 answers

Escaping the # character in .env file

The secrete API key I want to store in my environment file for my express server is ignoring half of it as it contains a # symbol in the middle. I can't regenerate the key. And do not want it to be left unsequre
Fardeen Khan
  • 770
  • 1
  • 9
  • 20
23
votes
3 answers

How to define array/object in .env file?

The following is my Javascript object: window.options = { VAR1: VAL1, VAR2: VAL2, VA31: VAL3, }; I want it (either object or array) to be defined in a .env file. How can I do that?
Trupti
  • 843
  • 2
  • 11
  • 28
1
2 3
54 55