0

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
Progman
  • 16,827
  • 6
  • 33
  • 48
koque
  • 1,830
  • 5
  • 28
  • 49
  • Do any of the answers [How do I setup the dotenv file in Node.js?](https://stackoverflow.com/questions/26973484/how-do-i-setup-the-dotenv-file-in-node-js) help? – Andrew Morton Jan 30 '22 at 15:33

1 Answers1

1

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})
Mot
  • 48
  • 6