3

I'm using the node-config module for mongo connection strings and jwt keys.

For example:

if(!config.get('jwtPrivateKey')){
    throw new Error('FATAL ERROR: jwtPrivateKey is not defined');

My custom-environment-variables.json file looks like:

{
    "jwtPrivateKey": "video-app_jwtPrivateKey",
    "db": "video-app_db"
}

default.json

{
    "db": "default db",
    "jwtPrivateKey": "default key"
}

production.json

{
    "db": "production db",
    "jwtPrivateKey": "production key"
}

long story short - although the environment variables are set in heroku, node-config doesn't look at the values set in custom-environment-variables.json. I can alter the NODE_ENV and get the relevant json file's hardcoded values, but the environment variables are never used, which seems to contradict the docs

1
  • Does this also happen in your local environment? looks like something it rewriting the variable env. Commented Apr 19, 2020 at 6:13

3 Answers 3

1

I had the same issue. It took removing the hyphen from the keys for heroku to read from custom-environment-variables.

So custom-environment-variables.json:

{
    "jwtPrivateKey": "video-app_jwtPrivateKey",
    "db": "video-app_db"
}

Becomes:

{
    "jwtPrivateKey": "videoapp_jwtPrivateKey",
    "db": "videoapp_db"
}

Heroku docs:

Config var policies

  • Config var keys should use only alphanumeric characters and the underscore character (_) to ensure that they are accessible from all programming languages. Config var keys should not include the hyphen character.
  • Config var data (the combination of all keys and values) cannot exceed 32kb for each app.
  • Config var keys should not begin with a double underscore (__).
  • A config var’s key should not begin with HEROKU_ unless it is set by the Heroku platform itself.
Sign up to request clarification or add additional context in comments.

Comments

1

You can config vars on this way in Heroku

2 Comments

I think I've created the vars correctly. Typing heroku config:get video-app_db returns the variable as expected. However, using node-config in my code to config.get('db') returns the value from default or production.json rather than the custom-environment-variables.json file. It seems to be a problem with node-config i guess? I'll edit my title to reflect that
If you suspect the problem is withnode-config, you can set the environment variable yourself (without Heroku) and see if it works. I believe you'll find it does. The problem appears specific to Heroku.
0

So, I had the same issue: I deployed my app, set environment variables in Heroku, but nothing worked (unlike my local machine where everything was fine).
Seems like the problem was that I accidentally added all the node_modules folder to git. It happened because I created a .gitignore file after the initial commit was made (if I get it right).

What I did, that worked for me: I removed node_modules from git and committed/pushed changes to Heroku:

git rm -rf node_modules

then commit and push.

This was the error message I got:

Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header

I spent two days trying to figure it out.
I hope it's helpful.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.