environment variables undefined
See original GitHub issueWhen I try to start the site (~p. 248), I’m met with the following error:
Unhandled rejection SequelizeConnectionError: password authentication failed for user "crash"
which caught me off guard because my .env file is:
DATABASE=gql
DATABASE_USER=postgres
DATABASE_PASSWORD=postgres
After going down the rabbit hole with Postgres and permissions and still not solving the issue I tried logging my environment variables only to find them undefined. (Really, that should have been the first place I checked).
I was able to fix the issue by updating /models/index.js and adding:
import 'dotenv/config';
I see it also exists in /src/index.js in the repo, but the book never specifies adding it anywhere. Updating the code for the index on p. 243 would save the reader a lot of troubleshooting.
Issue Analytics
- State:
 - Created 5 years ago
 - Reactions:1
 - Comments:7 (4 by maintainers)
 
Top Results From Across the Web
NodeJS environment variables undefined - Stack Overflow
I believe the nodemon. json file is only for setting nodemon specific configuration. If you look at the nodemon docs for a sample...
Read more >.env variables “undefined”.. Ever stuck in a scenario ... - Medium
Environment variables are simply variables that we want to use globally in our file system of the project but we don't want to...
Read more >Can someone explain me why .env variables are undefined ...
In my javascript file. require("dotenv").config(). console.log(process.env.MYVAR). In my .env file. MYVAR=A. logs undefined. I just can't make sense of REPL.
Read more >Environment Variable undefined at build time #38164 - GitHub
Hello! I am running into an issue with using getServerSideProps instead of an API route called from the client side to load data....
Read more >Working with Environment Variables in Node.js - Twilio
Environment variables are a great way to configure parts of your Node.js ... Here, you'll notice that the value of PORT is undefined...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Nevermind, I totally forgot that .env is ignored by git so I need to recreate it after pulling from my local repo. It’s all good, working now.
Had same issue, OP helped solve it.