Database for Mobile Dev

Hi guys I am looking to create an android app and later an IOS app that will require a database. I dont have the money or internet connection to create my own database. I think I could figure out SQL but what is the best service that will allow me to rent database space for this app I want to build?

Well depending on what you need, Amazon AWS or Digital Ocean will propably fit your needs.

If its a small database that will not get many requests, digital ocean has a 5 dollar a month box, thats what I host my site on.

Just get a DigitalOcean $5 droplet, install LAMP or NodeJS (with express) + MongoDB, set up the database and create a REST API. Don't let the app talk to the DB directly. Also make the database only accessible from localhost to make it invisible for the rest of the world.

1 Like

Just so we are clear you only need a remote DB? If you need to deploy a DB as part of the app as well then SQLite is probably what you need.

well I do plan on making a website to use the database as well.

If you just need a website and some database access, LAMP is probably fine. If you want to have a service sitting somewhere in the cloud to connect let's say various mobile and web apps to a database (or multiple databases or other services etc.), you should take a look at REST APIs. REST services can be implemented in various languages (like PHP, NodeJS, Python, Java, C#) - I think NodeJS is the best option for this since you don't need a lot of frameworks (compared to Java) and you can implement services very quickly using a few lines of code. Even better: NodeJS is faster and more efficient than Java when it comes to response times and big numbers of concurrent requests - also when using Java, you need a HTTP server like Nginx or Apache in front of your JavaEE app server as a reverse proxy - Java runs at port 8080 and can't run on 80 without root privileges - since you never want your Java app to be root user of your VPS, you need a reverse proxy to map the ports.

I got a droplet server now you recommend that run NodeJS with (express) and something called MongoDB on this server.


Yes, here is a link to express:
Here is a beginners tutorial:
Here is one that shows mongoose (NodeJS framework to connect to MongoDB):
MongoDB is a light-weight and robust NoSQL database. You can also use MySQL with NodeJS:

Hopefully that helps you to get the foot into the door.
For REST API debugging purposes there is a Chrome app called Postman.

1 Like

Do you have any ideas of how I could test my node.js web server after I did all the steps. I created a very basic html file with just one line of?
<p1>some text</p1>

The standard way is:

  1. set up the database (mongodb)
  2. create a REST API that connects to the database (express + mongoose)
  3. test the REST API using e.g. a unit test framework like JUnit, some JavaScript code or a REST client like Postman
  4. create your client with dummy DTOs and messages like "feature not supported, yet" i.e. without connecting to the server
  5. connect your client to the server using your REST API
  6. test your client, check your database for consistent data, check server logs (there are logging frameworks for NodeJS)


That is no valid HTML - <p> and <h1> exist; <p1> doesn't.

1 Like

i already feel bad for that debugger

Before I build the database I want to see if I can load any web pages locally and that html code I posted was not what I used as my index I used <h1>.

I also want to use mysql and not nosql because part of the purpose of this project is for me to learn some database tech and web dev stuff.

First of all: you shouldn't send HTML from the Server when you are creating a REST API. Sending HTML is only appropriate for MVC-based applications which use server-side-rendering. Use JSON objects instead and render them inside the client - not every client (e.g. website, android app, iOS app, Windows app etc.) can use that HTML - therefore you need a standard way to pass the information to the client and leave the rendering to client-side.

That's fine.

So here is, what you could do:

You could create a dummy DTO on the server-side - basically a static JSON object hard coded into your NodeJS app without a database connection which can then be retrieved by a REST call from a client.

Then on the client side, you simply use e.g. jQuery's get function to make the REST call.
You can then log the response in the client console using the console.log function.

I want this to be a web server as well if possible so that is why I want to test this.

I followed these instructions from above and it explains how to set up an index.html and a about.html and I presume that would be the base of other web pages that could load. I am wondering If I could test using this call http://localhost:3000 with ssh so I could load the html files I put into the directory the instructions told me to. Then I would feel comfortable to start working on the database stuff.

OK. This guide basically shows how to create a MVC application without M. Then you should prefix all your REST URIs with something like "/api/v1" (e.g. /api/v1/topics/mytopic - to retrieve the contents of topic in JSON format via REST).
Then you can have /about, /, /whatever etc. for your MVC web stuff and have your REST API on the same server.

NOTE: That is more or less a "hack" (no proper way to do that). A better way is to create two separate NodeJS apps listening to different ports and then use a NGINX reverse proxy in front of them which maps your MVC app to port 80 and your REST serivces e.g. to port 8080. Then requests from a browser to your MVC app can be made by http://<server_ip> instead of http://<server_ip>:<port>
The biggest benefit of this approach is the fact that your website and your REST services use separate processes. That means, if your REST services cannot handle the amount of requests, you can give the process higher priority so that the scheduler gives it more CPU time. If your server cannot handle that anymore, you can simply move your REST services to a new droplet and reconfigure the reverse proxy. That way, no client code needs to be changed - imagine having multiple clients for various platform which would all require an update since the API URI has changed - Reverse Proxy to the rescue.

When you are using ssh, you should be able to do: wget http://localhost:3000 on your server which should download the file retrieved by the server. Then you could use nano or cat to see the content of that file - but why would one want to do that, if it is possible to use http://<droplet IP>:3000 in a web browser?

I tried using http://<droplet IP>:3000 but it says refused to connect. I was wondering if you have any why that didn't work?

NVM I got it to work.

Can I create two different server.js files, one for the web pages and the other for the database?
Or do I have to create two different file structures?

I am not sure regarding my previous post, if it is possible to run a NodeJS app listening to port 80. In Java this is not possible. Maybe try to change the port to 80 before adding a reverse proxy - if NodeJS can use port 80 natively, you don't need a reverse proxy. Then you are able to use http://<droplet IP> in your browser.

I don't believe you can create multiple servers in one app - but I am not sure about that. Basically you don't need various server.js files but multiple server objects. But you can simply use my first suggestion and add a prefix to your REST services using one server object in a single server.js file of one NodeJS app. For a first project to get the foot into the door, this should be fine. If you run into performance issues (would be a miracle) you can still move your REST services to a separate NodeJS app.