React Native Expo use own REST API with local Database

Hello there I hope you are all good, I have some questions regarding React Native with EXPO.

I have created an App that depends on a postgresql DB and communicates with my own REST API. I have one Folder where my Frontend lives - here I query with my Computers IP address and with the routes I defined in my Backend.

Like this: 192.xx.xx.xx:8080/api/hours/getDay/:userid

My Backend is in another Folder - and I start the server with npm run server. Here I have setup all the routes and the connection to a postgresql db wich is running on a Docker.

First Question I have is do I need to put the Server Folder inside my Frontend Folder? I guess yes because I currently have 2 Folders - If I need to do that, how do I tell my App that it has to start both the server and the Frontend?.

Now the second thing I would like to know is, how can I for example use my app with the Expo app but still access the DB? I think I need to change the IP I query against and somehow make the DB run online and not on a Docker? I want to show the app on my private Phone wich is not connected to the same Network as my PC.

Sincerly Faded~

It’s not a good practice to merge server and client apps, unless they are mixed by design like Next+Expo. They can have different dependencies, configs - everything. A reasonable way to do this is to have nested projects in root project where start script runs both frontend and backend apps. They can be run separately or together this way.
As for the second part, I’m not sure I understood correctly, but you likely need something like ngrok. Or probably this is a time for server app to go cloud, even for development.

SO what if I want to publish my app - it has to be in One folder and the script should start both on App start - thats how I understood you. To the second thing - If my company has a DB we use it has to be reachable from outside so it has to be online or something right? And I want to use that connection to communicate with my app that writes and reads from that DB.

Yes, that’s correct. Depending on your case, you may want separate servers for dev and prod. As for local development, try ngrok.

ok ty for your advice - but how would the real app look like? lets say 50ppl need to use my app and access our db to save hours and check hours that they worked. If the db was accessible from the internet and I have a IP where I can query against, then my app just has to run with network enabled right? this ngrok is just to connect the device to a local thing right?

Yes, it is. ngrok applies only to a part where you wanted to test it on your phone while running a server locally. To run it in production for other users, you need to deploy it do remote server.

Alright thanks for the Feedback - I will come back to it if I have any Questions. Thanks :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.