koque
koque

Reputation: 2256

Why have the environment variables in my .env file stopped working?

My .env has been working forever but stopped working all of a sudden.

.env

LOCAL_PORT=4200
JWT_SECRET=afdafuwafjadgaqjfafads

server.js

require('dotenv').config();

const PORT = process.env.PORT || process.env.LOCAL_PORT;
console.log('process.env.PORT', process.env.PORT)
console.log('process.env.LOCAL_PORT', process.env.LOCAL_PORT)

process.env.PORT undefined
process.env.LOCAL_PORT undefined

Upvotes: 0

Views: 1695

Answers (1)

mot
mot

Reputation: 126

In many cases this a path issue. I recommend attempting to set the path explicitly and also turning debug mode on.

require('dotenv').config({path: path.join(__dirname, '.env'), debug: true})

Upvotes: 1

Related Questions