I have some problems with seeding a file. When I run my NodeJS locally it is quite easy to seed that file, but how the heck should I do that when it is being pushed to Heroku?
Could you show us your GitHub repo for the project so we can see how you’ve set it up?
Have you tried doing this on Heroku yet? If so, what error messages are you getting?
When Heroku is running, you can read logs in real time by having the command
heroku logs -t running in the terminal.
Heroku logs throws the following error:
2017-11-16T21:57:12.109278+00:00 heroku[router]: at=info method=GET path="/image /vivo-logo.png" host=vivo-app.herokuapp.com request_id=7baa9af8-2ed2-41d7-b25c-d d10fac12881 fwd=“220.127.116.11” dyno=web.1 connect=0ms service=1ms status=200 byt es=3576 protocol=https
2017-11-16T21:57:11.903485+00:00 heroku[router]: at=info method=GET path="/produ ct" host=vivo-app.herokuapp.com request_id=b3782fc7-184c-468e-9877-f47a525e2072 fwd=“18.104.22.168” dyno=web.1 connect=0ms service=9ms status=200 bytes=7794 prot ocol=https
Those don’t look like error logs to me, just regular system logs. Do you have any more than that? Error logs usually tells you an error code, or explain that the server crashed.
Usually, if it works locally, but not on Heroku, it’s because your ports (server or database) are hard coded rather than based on environment variables.
The app runs on Heroku, but how could I seed the seederfile.js. Locally you should run the command line “node seederfile.js” to get the data from this file.
Without seeing all your code, it’s hard to say.
If it works locally, you already know how to do it - Heroku just runs your code the same way.
There are quirks between Heroku and local development, which can be fixed by leaning on Heroku’s file path variables or environment variables.
If you link to a full repo, we can see how you’ve connected everything up and maybe help troubleshoot.
I suspect this is the issue:
mongoURI = 'mongodb://localhost:27017/smartphones';
In your app.js
Heroku can’t see your local host.
Look into a remote mongoDB like mLab.
If I replace it with this one:
Will it automatically connect to mongodb or should I run a command line first.
It’s been a little while since I used it, but if I recall correctly there is no other set up or command line action after the initial set up on the mLab website.
You can set the password for mLab in Heroku’s app variables and access using process.env… like you do with the ports.
I will contact mylab support team I guess…