Total beginner question: database connectivity

I have spent about 24 hours so far getting familiar with mobile apps. I have zero experience in Javascript/Android but have done programming in C++/C etc. before.

I would like to start by asking the following two questions:

  • How does a hybrid app run? (node.js runs on mobile phone and deploys the app?)
  • How does the app connect to a remote database? (if the app is in JavaScript, don’t we risk exposing mysql username/password for example?)

If someone can answer the above or point me to some good tutorials I’ll be grateful!

1 Like

Typically you would have your app connect to a server which provides an interface to your data which can be stored in a database. With ionic you can either create a REST api which is just fancy http calls, or you get fancy and try to use websockets. Either way would work but right now most people are using REST api’s since most things don’t need a constant connection to the server. By running a server you also avoid having to expose db auth info to your client since your server acts as a middle man and regulates all changes.

Also if you do end up using a REST api I’d suggest you read this post which is an excellent guide to the do’s and dont’s of making a good REST api.

1 Like

Thank you very much! I had started reading up on REST but the article you pointed to is great.
Is there a block diagram somewhere of the ionic framework that I can look at?

I don’t know if theres any block diagrams but basicly just make sure you store your rest related things in a service and use $resource or rest-angular to connect to your server. Then bind to your service object in your controllers to access the data you receive from your resources.

If you need more help I’d suggest hanging out on irc in #angularjs and #ionic they helped me alot when I first got started. Plus you get to learn from other peoples problems.

Just to add on what @epelc has already mentioned. The remote connection to the database is normally done in two ways. REST calls or a HTTP call.

In my case, I use the $resource from angular to make a REST call to a node.js that I have on my remote server. The node.js receives the REST call, interprets the parameters and does a insert/retrieval/update/delete of records by connecting to a Mongo DB ( this is what I am using for a given application).

If you put it into a diagram, your Client Side ( JavaScript) will never interact to the database directly, it will reach out to intermediate entity (Node.JS in my case).

If you are concern about username/password disclosue, you can look at the different methods of authentication, e.g OAuth for a token based interaction with the Server.

Thank you. I will be using OpenFB in my app to authenticate users via facebook. The question is, after authentication, I want to be able to update my own database somehow. How will that be possible?

Lets say the steps are:

  • User starts app
  • App asks for login
  • User enter FB username/password, gets authenticated
  • The app now connects to my own server and asks user to fill out a profie/form. Profile gets saved on remote server so that it can be accessed online via web.

How do I accomplish the last step? Is there an existing app which does something similar?

edit: I’ve started looking at this, is this a goot starting point?

1 Like