question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

environment variables undefined

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jakec-devcommented, Mar 5, 2019

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.

0reactions
krynvcommented, Sep 5, 2019

Had same issue, OP helped solve it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found