Using MongoLab in Heroku doesnt work unless I provide CC number? - node.js

I have developed a nodeJS application using Angular as the front-end (used MEAN stack and plan to use Bootstrap with it) and when I try to deploy it to Heroku, whenever I run this line: heroku addons:create mongolab I get the following output:
bruno#bruno-HP-epicsauce:~/herokuFinalApp$ heroku addons:create mongolab
! Please verify your account to install this add-on plan (please enter a credit card) For more information, see https://devcenter.heroku.com/categories/billing Verify now at https://heroku.com/verify
bruno#bruno-HP-epicsauce:~/herokuFinalApp$
And in both sites (mongolab and Heroku) it says it's free... I have already defined the heroku env variable called MONGOLAB_URI, like this:
bruno#bruno-HP-epicsauce:~/herokuFinalApp$ heroku config:set MONGOLAB_URI=mongodb://USER:PASS#ds041643.mongolab.com:41643/dbNAME
Setting config vars and restarting rocky-sea-9859... done, v4
MONGOLAB_URI: mongodb://USER:PASS#ds041643.mongolab.com:41643/dbNAME
bruno#bruno-HP-epicsauce:~/herokuFinalApp$ heroku config | grep MONGOLAB_URIMONGOLAB_URI: mongodb://USER:PASS#ds041643.mongolab.com:41643/dbNAME
bruno#bruno-HP-epicsauce:~/herokuFinalApp$
It still doesnt work...
In the git repository I have the following file structure:
The app is listening on the port: process.env.PORT instead of some local one and the package.json file contains the correct dependencies as it was automatically generated with npm init.
Inside the procfile I have the usual reference to the file that contains my server side code:
web: node server.js
The app.js contains the Angular client-side code.
Is there any 100% free way of deploying an app in Heroku with a DB hosted somewhere?

You have two options to use MongoLab services on Heroku:
Connect to existing MongoLab deployments from Heroku (no credit card required)
Add MongoLab as a Heroku add-on (credit card required)
Since you have set up MONGOLAB_URI, I assume you created a separate account with MongoLab and created a new MongoDB deployment. In this case you don't need an addon. If you have your MongoDB driver configured to use the connection URI, setting MONGOLAB_URI config on Heroku is usually enough.
More info on this here
Heroku asks for a credit card for verification purposes. It won't charge you unless you choose paid addons.
You must verify your account if you want to:
Add any add-on to your app, even if the add-on is free. The only exceptions to this are the free plans for the Heroku Postgres and Heroku Connect add-ons, which can be added without verification (source)

A message from their staff:
You won't be charged if you only use the free plan. Unfortunately some
people use free add-on plans for evil purposes so we need a way to
verify the account. Right now we do that by requesting a valid credit
card, and we may add more verification mechanisms in the future.
I'm in the same point than you, but as you can read, there is no problem to add that information (but to be honest I'd prefer another way as well).

I don't know it will actually charge you, it just wants CC to verify. But you could always just use http://progrium.viewdocs.io/dokku/ or Digital Ocean VPS (which is not actually harder than setting up your dev machine as long as you aren't expecting perfect security etc.).

You do not need mLab MongoDB add-on, just manually add Config Vars

Related

How to use get cf ssh-code password

We are using CF Diego API 2.89 version, Currently I was able to use it and see the vcap and the app resources when running cf ssh myApp.
Now it's become harder :-)
I want to deploy App1 that will "talk" with "APP2"
and have access to to it file system (as it available in the command line when you run ls...) via code (node.js), is it possible ?
I've found this lib which are providing the ability to connect to ssh via code but not sure what I should put inside host port etc
In the connect I provided the password which should be retrieved
via code
EDIT
});
}).connect({
host: 'ssh.cf.mydomain.com',
port: 2222,
username: 'cf:181c32e2-7096-45b6-9ae6-1df4dbd74782/0',
password:'qG0Ztpu1Dh'
});
Now when I use cf ssh-code (To get the password) I get lot of requests which I try to simulate with Via postman without success,
Could someone can assist? I Need to get the password value somehow ...
if I dont provide it I get following error:
SSH Error: All configured authentication methods failed
Btw, let's say that I cannot use CF Networking functionality, volume services and I know that the container is ephemeral....
The process of what happens behind the scenes when you run cf ssh is documented here.
It obtains an ssh token, this is the same as running cf ssh-code, which is just getting an auth code from UAA. If you run CF_TRACE=true cf ssh-code you can see exactly what it's doing behind the scenes to get that code.
You would then need an SSH client (probably a programmatic one) to connect using the following details:
port -> 2222
user -> cf:<app-guid>/<app-instance-number> (ex: cf:54cccad6-9bba-45c6-bb52-83f56d765ff4/0`)
host -> ssh.system_domain (look at cf curl /v2/info if you're not sure)
Having said this, don't go this route. It's a bad idea. The file system for each app instance is ephemeral. Even if you're connecting from other app instances to share the local file system, you can still lose the contents of that file system pretty easily (cf restart) and for reasons possibly outside of your control (unexpected app crash, platform admin does a rolling upgrade, etc).
Instead store your files externally, perhaps on S3 or a similar service, or look at using Volume services.
I have exclusively worked with PCF, so please take my advice with a grain of salt given your Bluemix platform.
If you have a need to look at files created by App2 from App1, what you need is a common resource.
You can inject an S3 resource as a CUPS service and create a service instance and bind to both apps. That way both will read / write to the same S3 endpoint.
Quick Google search for Bluemix S3 Resource shows - https://console.bluemix.net/catalog/infrastructure/cloud_object_storage
Ver 1.11 of Pivotal Cloud Foundry comes with Volume Services.
Seems like Bluemix has a similar resource - https://console.bluemix.net/docs/containers/container_volumes_ov.html#container_volumes_ov
You may want to give that a try.

MongoLab DB is not responding when using with localhost

I have an Heroku web applicaiton based on MongoLab MongoDB.
Accessing the site via heroku production site works and I see the site is alive.
My development environment is configured to work with the production DB.When I try to connect I get on:
mongoose.connection.on('error', function(err) {
...
});
And err.message = "connect ETIMEDOUT 54.159.67.179:61188"
How should I continue?
If you click through the resources section of the heroku dashboard and then open your mlab resource it should take you to the mlab home.
The first bit of information should show you how to connect to your database either though the mongo shell or using the standard URI. If you have mongo installed locally can you connect to the remote database this way? If not then it points to network issues. Are you accessing this from behind a corporate proxy? Mongo by default uses port 27017 which isn't open on most corporate proxies. If this is the case then I would speak to your network administrator. I know that at my company we aren't allowed to use this port, but then we don't use cloud infrastructure (yet). Good luck!
I faced the same issue. Solution for me ended up that the environment variable (stored in a .env file in my app) had an old "configvar" (Heroku terminology) and:
go to the desired app Settings tab in Heroku
click the Reveal ConfigVars button
copy the MONGODB_URI value
paste the URI into the .env file (or wherever you store)
That was it, back in business.

How to deploy live Node.js server using Heroku

Sorry for confusing title, new to Node.js and Heroku, but trying to quickly pick it up.
I currently own a domain, and my first goal is to have it set up so I go to the domain, it uses Heroku to wake up and run Node.js, run my web.js, and display "Hello world".
I've already gone through this heroku/node.js tutorial, and so I understand how to set up stuff locally, push to the heroku remote, and run my Node.js server with it (am I understanding that correctly?). However, I couldn't find anything for how you actually put your Node.js files onto your external server (so, in this case, my domain), and connect the service of Heroku to those files, allowing my local machine to interact with the node on my server.
If there's any tutorials or pages you'd recommend, I'd appreciate it. Kinda stuff and most likely confused on quite a few things here. Thanks!
Heroku apps have their own git repository. So, you push from your local git directory to heroku's git remote.
Setup:
git remote add heroku <git://yourherokurepourl.git>
and then every time to deploy:
git push heroku
That's all needed to get your node.js files on heroku's server. Heroku follows foreman as process launcher. foreman needs a special file in project root called procfile. procfile has simple unix commands to launch processes in each line :
web : npm install && node app.js
So, when you push your project to heroku's git. It will look for procfile and launch processes defined there. You can place more commands here. Better install foreman on your local/development machine and test using that.
In heroku app settings you can "bind" your www.domain.com address to node app running on heroku's server. You have to do the same in settings of domain provider. The DNS will now route requests to www.domain.com to your app's server IP.
On heroku, configuration lives in environment. A lot many process.env.* are available on heroku. You can locally simulate this by providing .env files to foreman.
finally, in your node.js code make sure you listen on value provided by process.env.PORT.
Connecting servers:
Use Request module to directly call other server urls.
Or, Let server's subscribe and publish to a centralized service bus.
You are describing operating two servers. One on Heroku, one "on your domain". I suspect you haven't made the connection that you can merely get your domain to point to your Heroku server. Contact your domain name provider with the heroku url you are using and they can do this for you.
In effect they will "point" your domain to your Heroku node.js server and from there it will act as you expect.

Connecting to Redis databases via Node in Heroku

About Heroku: App is Nodejs, Express, WebSockets ...
I'm testing an app out on a small free Heroku instance.
I have my own Redis database instances through OpenRedis and RedisToGo.
Those have not been provisioned through Heroku addons but directly from the providers.
I connect to them fine when running locally. What special do I need to do to connect to them through Heroku?
I was kind of hoping to avoid special Heroku-specific environment variables, but am happy to use them if necessary.
But I definitely need to avoid the necessity of provisioning the Redis addons through Heroku.
Again, I have already my database instances provisioned directly with the relevant providers.
Everything works fine locally under NODE_ENV=production npm start, which indicates to my app that it should connect to the remote Redis instances (RedisToGo and/or OpenRedis) instead of the local Redis server.
I'm using Redis for at least three things:
Session store :: Connect-Redis :: This works fine locally (app server running locally but connecting to remote Redis instance) and also seems to work on Heroku-- I've checked by flushing the database and then pushing a slightly new version to Heroku and the session variable key is refreshed.
Database :: Node-Redis :: This works fine locally also (also app server running locally but connecting to remote Redis instance for database), but does not seem to be working on Heroku.
WebSockets Transport Pub/Sub :: I haven't tested this thoroughly. I'm guessing it's working but it's not important for this question.
What is most interesting to me,
is that the Heroku instance is able to connect to the Redis instance via the Connect-Redis client, but is not able to connect to the same Redis instance via the database client. Whereas my locally running version is able to connect to the same (remote) instance via both of these clients. (I have verified these findings through terminal clients, using flushall command and waiting for keys to be refreshed.)
Any insight would be greatly appreciated.
I'll post my edits and updates via comments below because they're timestamped.
It turns out we can't connect to a database (not sure why because I don't know the internals of Heroku's config over AWS) the 'normal' way through Heroku; we need to set the environment variable with the heroku config:set command. OpenRedis provides a terminal ready string, can probably put something similar together for self-provisioned RedisToGo instances, though I haven't done it yet.

Deploying a TCP server to Heroku

I have a TCP server coded in node.js. I'd like to put it up on Heroku because it's a free service and I don't need anything more than what their free plan offers.
Now, I know very little about the inner workings of Heroku and I'm pretty new to the whole thing so I have a few questions.
Firstly, is it even possible to deploy a TCP (non-web) server? I've read that Heroku doesn't like node.js's net because it doesn't support websockets and that I should use socket.io.
So I've switched my server to socket.io. I think. Because my code more or less looks the same. I've done this as well: https://devcenter.heroku.com/articles/using-socket-io-with-node-js-on-heroku
What do I put in my Procfile instead of "web"? Also, when I tried to deploy what I currently have, the logs said that my application failed to bind to $PORT. What's $PORT? And how do I change it to the port I want?
In fact, if I don't change it, how do I know what it is so my application can connect to this server?
The free tier of Heroku does not support TCP server. Here is the reason.
To save costs and offer free services, Heroku hosts multiple free-tier apps on the same machine. These apps, one of them being yours, share the same IP address. The apps are assigned to different ports.
However, as you probably noticed, when you access your app in a browser, the port is always 80. Hence, to know which app an incoming HTTP request is looking for, the server must be looking into the HTTP headers. (For example, using HOST to find out the app name, then resolve the app name to an internal port number.)
Finally, Heroku decided to hide away the internal ports from the internet. This, along with the fact that TCP connections don't have a HOST field, makes it impossible to host a TCP server with Heroku.
To work around this, use WebSocket.
Appendix: the Research
Testing was done with a free-tier Heroku app, in March 2020.
If you make up a non-existing app name (e.g. https://hr.herokuapp.com), Heroku responds with a page saying "There's nothing here, yet."
If you first manually nslookup an existing app (e.g. https://world-of-blogs.herokuapp.com), then try to use the IP address to access the app, Heroku also responds with a page saying "There's nothing here, yet."
Heroku doesn't support a generic TCP server but you should be able to get the functionality you want with socket.io.
You need to put web in your Procfile. That's what lets Heroku bind an external connection to port 80 to the local port your web traffic will arrive you. You find that port by looking at the environment variable $PORT. More info, with examples, is here: https://devcenter.heroku.com/articles/nodejs

Resources