20210916 - Manually set environment variables to Heroku
2021-09-16 00:00:00
Option 1:
We defined the environment variables for development in file .env, but the environment variable that defines the database URL in production should be set to Heroku with the *heroku config:set* command.
1 | $ heroku config:set MONGODB_URI=mongodb+srv://fullstack:secretpasswordhere@cluster0-ostce.mongodb.net/note-app?retryWrites=true |
NB: if the command causes an error, give the value of MONGODB_URI in apostrophes:
1 | $ heroku config:set MONGODB_URI='mongodb+srv://fullstack:secretpasswordhere@cluster0-ostce.mongodb.net/note-app?retryWrites=true' |
Option 2: (recommended!)
Heroku App → Setting → Config Vars
I’ve set MONGODB_URI via git bash but it didn’t work, so I tried one more time by manually setting it on Heroku. It worked!