Connect to MongoDB database using mongoose behind a proxy - node.js

I am using mongoose to connect to my database in mongolab in my server.js file :
mongoose.connect('mongodb://MyUsername:MyPassword#ds089702.mongolab.com:89702/todo');
When i launch my server with node server.js command, i see this error in my terminal
failed to connect to [ds089702.mongolab.com:89702]
I am very sure that is just a corporate proxy problem, so I'm wondering how can I connect to my database over the corporate proxy using mongoose ?
Thank you!

I had the same problem and figured out a solution that worked for me.
Example mongodb URI:
mongodb://:#ds123456.mlab.com:37409/dbName
Use a proxy client (e.g. Proxifier).
Create a HTTPS proxy through port 8080 using your corporate proxy as the address.
Create a rule for mlab using your URI's port as the target port, which uses the HTTPS proxy you created above as its action.
Prioritize your mlab rule high in the rules list.

Related

Connecting to Mongodb without Auth?

I have Mongodb installed on my Ubuntu server. I allowed the server IP in the database config file. Port 27017 is open. The auth is off on the database meaning everybody is supposed to be able to connect to it via this URI string using Compass:
mongodb://<server IP address>:27017
with all this conditions ongoing, I still cannot connect to db with this URI string. Why?

Cannot establish connection using port number explicitly

I am new to servers and networking so pardon my ignorance.
I have a Heroku application running a NodeJS server. I am using console.log() to output the port its using to the console. But when i use the port to try to perform a GET request from my browser it keep loading forever. My request is something this:
https://example.herokuapp.com:28222/getHighest
When i remove the port number, it works perfectly:
https://example.herokuapp.com/getHighest
I am ultimately trying to perform GET and POST request from a C application. The HTTP library i am using seemingly requires a port for a connection. I am using this library: GitHub. It works perfectly when i run it locally with localhost:8080/getHighest but not when i use my heroku app.
As suggested by #tadman using the default https port 443 solved the issue.

node server placed behind proxy server failed to GET request to https://localhost:<port>

On my machine, im hosting a node server that is listening on port 5000. Before setting up a forward proxy (squid), i was able to perform a GET on https://localhost:<port>. However, after setting up a forward proxy and setting the environmental variable http_proxy=<ip addr:port>, this GET request no longer works.
The error that shows up is: tunnelling socket could not be established, statusCode=503
Some additional information:
The proxy server works as I am able to connect to the internet via it.
Performing curl instead, on the https:localhost:5000/api works.
Am using request.js for the requests, using agentOptions to specify TLS protocols & ca cert.
I am hoping to understand how the traffic is now different after i add in a proxy. From my understanding, now we have to go through a sort of TLS CONNECT / tunnelling since to the proxy first, since its a HTTPS request, before coming back to my localhost. But in the case without the proxy, how is it that its working?
Any help would be greatly appreciated. Thanks!
you must add
export no_proxy='localhost,127.0.0.1'
the https work because you don't use proxy for https , you must set https_proxy='<tour_proxy>'

How can I connect my ionic app to cpanel node server?

I'm developing an ionic app which has to be connect with cpanel node.js mysql server. when server runs in cpanel it shows as server is running. but I can't send requests from my app to the server. I'm confused with the server IP and port.
for node js server index.j file I have used port 3000 and host as localhost including mysql db username and pw. I tried to get response by using
url:http://(my cpanel Ip):3000/
var con = mysql.createConnection({
host: "localhost",
user: "bdruser",
password: "ABCD",
database: "users",
multipleStatements: true
});
when I send the requests by using postman it shows as could not get any response
Sorry but you are miles off from getting this right, and I can't give a simple fix:
You must use https for feeds or Android won't play nice.
You cannot connect to a mysql because then the servers password would be in your apps code and be a security risk
You are not connecting to the server in the right way anyway, localhost would only work if you were running that code on the same server as the mysql database.
Node.js is not for using within Ionic apps.
What you need to do is something different but its not simple:
Set up a website on your cpanel server
Set up a webservice on there
Secure the webservice in a way that you can access it from Ionic
Connect the webserver to the mysql database
Write code to expose the data you want through the service
I have fixed my issue. Whats wrong was firewall has blocked my port 3000. After it unblocked now my app is working very well with the cpanel backend server.
Thanks!!

How to connect node app to node api with Nginx

I built a Node app using this tutorial. Then I built a Node API using this tutorial. The app uses the app on port 4000 to connect to the API which then connects to a mongodb to store the info on the server.
This setup works great on my local machine, but I'm trying to deploy it on a digital ocean droplet. I have Nginx setup to listen to port 8080 for the main app. I'm able to navigate to the app. But when I try to register a user and submit the data to the API I get the following error in my browser OPTIONS http://localhost:4000/users/register net::ERR_CONNECTION_REFUSED.
I suspect I have to specify something in the Nginx config files. Or would it be a ufw issue? Any help would be much appreciated.
The error is very clear. The application try to fetch on localhost:4000, so you expect any visitor of your web app to have the API launched on their own computer.
Change your code to point to the correct host and port of you server.
Then, as you guess it, you will have to create a little Nginx configuration to tell him what to proxy to the APP and what to proxy to the API.

Resources