Tell us what’s happening:
Describe your issue in detail here.
When I run the app locally it connects to the database and list all collections. But when I deploy it to Heroku via Git the third test fails: “mongoose” should be connected to a database
What am I missing?
Your project link(s)
solution: https://dm-mongo.herokuapp.com
application: GitHub - danmikes/dm-mongo
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36
Challenge: Install and Set Up Mongoose
Link to the challenge:
On localhost it is now working:
http://localhost:3000/_api/is-mongoose-ok
gives:
{
"isMongooseOk": true
}
but on heroku it is not working:
https://dm-mongo.herokuapp.com/_api/is-mongoose-ok
gives:
{
"isMongooseOk": false
}
So is it not retrieving the .env?
I added the following:
a secret on github:
name=MONGO_URI
value=<uri to mongo-db>
an action to github:
file=.github/workflows/main.yml
content=
name: CI
on:
branch
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: retrieve environment variables
env:
process.env.MONGO_URI: ${{ secrets.MONGO_URI }}
run:
npm install
But still not working. Does anyone have an idea how to make the remote build retrieve the environment variable?
Thanks for the link. Maybe the information I need is in there, but I can’t translate it to my situation with mongo.
You can set a configuration variable directly on Heroku, which you can access in your code with process.env.VAR_NAME
. That way you don’t need to set the variable inside a .env
or yaml file.
1 Like
I understood the idea, but I am not able to convert the code in the example to my code.
Fantastic. I was setting the secret in github, but heroku needed it. Super! Thanks a lot!
1 Like
system
Closed
January 28, 2022, 8:21am
9
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.