I am trying to push my web application (MERN stack) to Heroku but I keep getting this error
What I have tried in index.js
if (!config.get("jwtPrivateKey")) {
throw new Error('FATAL ERROR!!: jwtPrivateKey is not defined')
}
console.log(config.get("DB"))
console.log(config.get("jwtPrivateKey"))
This is their value when i log them
at the config folder there are two files default.json and custom-environment-variables.json default.json
{
"jwtPrivateKey" : "",
"requiresAuth": false,
"DB":"mongodb+srv://****/test"
}
custom-environment-variables.json
{
"jwtPrivateKey" : "RhinoJohn_jwtPrivateKey",
"DB": "Rhinojohn_DB"
}
When i run heroku config here are the variables enter image description here
I have checked this question but none of the answers solves my problem. How do i solve Configuration property "jwtPrivateKey" is not defined?? I'm out of options
You can also use environment variables instead of files as heroku supports them just fine and use them as
process.env.VARIABLE_NAME
Beacsue you are using react inside the.env file you will need to store them as
#.env file
REACT_APP_SECRET_NAME=secretvalue
meaning that is has to start with REACT_APP_
don't forget to add it inside the gitignore file if you're using git.
You should add the secrets as configVars in heroku via your dashboard. Navigate to the settings page first once in the app.
Select settings and look for this
once you reveal them you can add the same values from your config files, the keys and values should match 100% to what you have in your keys.config file or whatever file your storing the secrets in.
This is how i hav always done it to avoid posting config files on public repos
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.