the-road-to-graphql / fullstack-apollo-express-postgresql-boilerplate

💥 A sophisticated GraphQL with Apollo, Express and PostgreSQL boilerplate project.
https://roadtoreact.com
MIT License
1.2k stars 265 forks source link

environment variables undefined #50

Open matthewboman opened 5 years ago

matthewboman commented 5 years ago

When 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.

rwieruch commented 5 years ago

Hi @crashspringfield Thanks for reporting this. It's mentioned over here https://www.robinwieruch.de/minimal-node-js-babel-setup/ with the order of importing as well. But you are right, maybe it should be mentioned again for environment variables. It's too easy to run into an error with them. Sorry again!

jakec-dev commented 5 years ago

I'm getting the same issue but adding that import to /models/index.js didn't solve it for me. I followed the steps listed in the readme, no other changes made, and get the following error:

Unhandled rejection SequelizeConnectionError: password authentication failed for user "root"

jakec-dev commented 5 years ago

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.

rwieruch commented 5 years ago

Related https://github.com/the-road-to-graphql/the-road-to-graphql/pull/24

rwieruch commented 5 years ago

Finally added over here: https://github.com/the-road-to-graphql/the-road-to-graphql/commit/643356c26ba9b3ee3184131216d769e689d898a5 I keep this issue open for people with the old version of the book though.

rwieruch commented 5 years ago

Anyone who runs into this issue and finds this issue, please comment. If I find no comment here the next time I get to this issue, I will close it :)

krynv commented 4 years ago

Had same issue, OP helped solve it.