Get [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017] when I deploy my project in heroku - node.js

My project works fine locally.
And I push my project into GitHub and Heroku by using command:
git add .
git commit -m "msg"
git push
git push Heroku
I got error when I tried to access https://still-shelf-36108.herokuapp.com/
I checked Heroku logs. The error is below:
READY Server listening on http://127.0.0.1:12211 15:03:24
2019-02-28T15:03:24.419308+00:00 app[web.1]:
2019-02-28T15:03:24.729864+00:00 app[web.1]: (node:42) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
Anyone can help to solve this?

The reason you are getting this is that your localhost and the Heroku's localhost are not the same. Therefore a database hosted on your localhost is not accessible from https://still-shelf-36108.herokuapp.com/.
To solve this, you can create a free MongoDB instance at https://www.mongodb.com/cloud/atlas and then connect from both your localhost and from your Heroku app.

Related

'Connection timed out' when connecting on heroku database using 'pg:psql' command

I am trying to connect to my database on heroku, which I would use on my app. I'm using either Command Line or Git Bash on windows.
I have created database on heroku named postgresql-rectangular-87454 and installed Postgres without any errors.
Typing heroku addons I'm making sure, database is set up:
$ heroku addons
Add-on Plan Price State
──────────────────────────────────────────────── ───────── ───── ───────
heroku-postgresql (postgresql-rectangular-87454) hobby-dev free created
└─ as DATABASE
but when I try to connect it via heroku pg:psql or also heroku pg:psql postgresql-rectangular-87454 --app salty-shelf-36209, I get this error:
$ heroku pg:psql
--> Connecting to postgresql-rectangular-87454
psql: could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "ec2-54-225-97-112.compute-1.amazonaws.com" (54.225.97.112) and accepting
TCP/IP connections on port 5432?
Any advice would be appreciated. Thank you!
Without knowing more, my first guess would be network rules -- that the connection is being blocked by a local firewall. The pg:psql command simply grabs the DATABASE_URL from your application config and passes the connection string to your local psql command to create the connection. If you're behind a corporate firewall, you may need to speak with your IT department about making an outbound connection.

Azure with Docker continer

I am creating a PHP application(7.1) using docker container, after configuring the docker container I am unable to connect to the SSH getting the below error
SSH CONNECTION CLOSE - Error: getaddrinfo ENOTFOUND Couldnt connect to main site container Couldnt connect to main site container:2222Error: getaddrinfo ENOTFOUND Couldnt connect to main site container Couldnt connect to main site container:2222Error: connect ECONNREFUSED 172.18.0.4:2222Error: connect ECONNREFUSED 172.18.0.4:2222Error: connect ECONNREFUSED 172.18.0.4:2222 CREDENTIALS
please review the below screen cast for steps I followed
https://www.screencast.com/t/iB1lVK98n
Thanks
For a custom docker image, you need include port 2222 in the EXPOSE instruction for the Dockerfile. Although the root password is known, port 2222 cannot be accessed from the internet. It is an internal only port accessible only by containers within the bridge network of a private virtual network.
EXPOSE 2222 80
More information about this please refer to this link.
You also could check this dockerfile.

Heroku NodeJs Postgres Heroku pg:psql - Connection Timeout

I'm following the tutorial:
https://devcenter.heroku.com/articles/getting-started-with-nodejs
I have everything working until the provosion a database step. My code is exactly the same as theirs, but for some reason I can't connect to
heroku pg:psql
It says Connecting to DATABASE_URL and then the connection times out. Does anyone know what's happening? I set the DATABASE_URL following the format:
"postgres://*USERNAME*:*PASSWORD*#*HOST*:*PORT:/*DATABASE*"

Deploy meteor app in Azure on Windows

Hello i am have meteor app and want deploy on Azure on Windows, i try it by Meteor Up but can't do it
***\project2>npm install -g mup
***\project2>mup init
Meteor Up: Production Quality Meteor Deployments
------------------------------------------------
Empty Project Initialized!
***\project2>mup setup
Meteor Up: Production Quality Meteor Deployments
------------------------------------------------
Started TaskList: Setup (linux) [23.101.74.119] - Installing Node.js events.js:85
throw er; // Unhandled 'error' event
^ Error: connect ETIMEDOUT
at exports._errnoException (util.js:746:11)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1000:19)
this error in Command Prompt of window from my local system
Looking at the error description it might be a connectivity issue. If you could share your mup.json file we might be able to spot the issue there.
Did you create an endpoint on TCP port 80? Check you nodeVersion setting so it corresponds to you Meteor app. The ROOT_URL should be in the format http://[myappname].cloudapp.net.
Using mup logs -n 50 you might detect some clues.

Nodejs in Openshift MongoDB Error

This could probably be very stupid and naive question, but I have tried all my ways to find the solution, but I'm unable to solve. Hope anyone can solve my problem. Thanks in advance.
Recently, I deployed my nodejs application in Open Shift using Mongolab driver for the MongoDB. When I run the application using 'rhc app start -a nodejs', it gives me an ECONNREFUSED error in mongooose.
Error: connect ECONNREFUSED
at errnoException (net.js:905:11)
at Object.afterConnect [as oncomplete] (net.js:896:19)
But, when I SSH into the server, go to $OPENSHIFT_REPO_DIR directory and use npm start, the app works very fine.
I connect to the mongodb by defining the URI as shown
mongoose.connect(process.env.MONGOLAB_URI || 'mongodb://localhost/<dbname>');
I defined the MONGOLAB_URI as an environmental variable in the server.
There would probably be something that I'm missing. But, please bare with this naive.

Resources