Run express server when react app runs on the web - reactjs

I have a basic react app which makes a call to an express server. In my localhost i can run the server with the command nodemon server.js and then my react app successfully makes calls to the server (which sends emails, it all works fine)
The issues is i must run the server everytime i want to let my app contact my server, but when i will deploy my app to my web hosting, the client using the website cannot run the server, needless to say. So my question is what can i do to resolve this?
I've just started backend dev so go easy please. thanks

You will have to find a place to host your Node.js backend. There the service will continuously run and will be accessible from the internet. You could either rent a server or go with a serverless approach (like Netlify or countless other providers).

Related

How can I run my next.js app on my live web server? Getting 300 Access denied error

Trying to build my first next.js app with little experience beyond the php/mysql world and running into a gap in my understanding. I have access to a remote VPS that runs my many websites that I can access through the web. Let's say I installed the app in /www/my-app
All tutorials on next.js speak of running typing 'npm run dev' and deploying my app through localhost:3000 on a local development server. No search engine seems to understand my problem that I want to run this on a remote server and not locally.
I've created an app through create-next-app. Calling the folder by URL (url.com/my-app) gives me a 300 Access denied. Not sure what should have happened or how I should access my app.

Dockerized ReactJS & Express on Elastic Beanstalk

I'm working with a startup to build an app. I've been studying CS for 2 years, so I'm new to lots of things. For our app we have a ReactJS front-end, Express back-end, and MySQL database. Currently it's deployed on AWS Elastic Beanstalk in a NodeJS environment. I configured it to run react-scripts build after it's been deployed. It's serving the static React-generated files through the Express server (bad idea, I know). This has worked for a while, but now the instance is running out of memory when trying to build.
I've been looking into Docker as a better solution (I've never used Docker before this week), and now I have a local development setup with 3 containers: a MySQL container, a Node container running the backend, and an Alpine container just running react-scripts start. The front-end is using a proxy to connect to the backend. This is all working fine locally (except that my backend container can't connect to the Internet so an external API is broken), but I have no idea how to deploy this correctly to AWS.
With Elastic Beanstalk is there a way for me to build and deploy a single Docker container with the pre-built React front-end, configure Nginx to serve those static files, and then pass all /api requests to the Express server? I'm using RDS for the database, so I don't feel like I need to deploy another container for MySQL.
I don't expect you guys to solve my problem, but I'd appreciate being pointed in the right direction. Maybe I'm going about this completely the wrong way.
React App:
I suggest you deploy your react application on AWS Amplify. you can find resources on how to deploy on the internet very easily.
MySQL
You can host your MySQL database on an EC2 instance or use any other hosted service for the database.
Express App
Now you can host your express app on EBS using the docker platform. You can also get the resources for this on the internet.
===========================================================================
Now add your express app endpoint in AWS Amplify's environment to use it with react app.
Add MySQL URL to EBS's environment to use it with Express App.
Note: AWS amplify serves your app on HTTPS so you have to enable SSL on EBS also. You can do it with the AWS certificate manager by
getting an SSL certificate and attaching it to the EBS.
It will be easy if the domain is handled by Route53 but again you can also achieve this with any domain service provider.
It is recommended that you should migrate your domain to Route 53, as you will get more control and also many other benefits.
Refer this answer: https://stackoverflow.com/a/38225802/9323655
Hope my answer will guide you in the right direction.

Facing problems to host react front end and connecting it to flask backend on azure cloud

I have the code ready for deployment and it’s working perfectly on the local computer. Flask as the backend (localhost:5000) and React as the front end (localhost:3000). I could host the backend code sucessfully but when I tried to host the front end separately it’s not working After deployment it says Application
and when I check the logs it’s all good no problems or error shown over there.
I also need some idea on how to connect it in Azure cloud as I don’t have much experience. I tried the solutions provided in some of the older discussions here
I can’t use virtual application because the flask backend can only be hosted on linux on Azure.
I have been trying to solve it since days.
Any suggestion on how to deploy and connect both will be helpful.

My heroku app works on my pc but on others pc or smartphone it doesnt let the backend working

My Heroku app works on my pc but on others pc or smartphone it doesn't let the backend working.
what should I do its a weird error?
here is the link of my repo / here is the link of the Heroku app Google books search mern
After looking at your repo, I would double check your database and API calls. In your client, you are fetching data from a localhost URL. If you are running React client side, the API call will try to fetch information locally on your device instead of from the Heroku server.
It's working on your desktop because you most likely have a MongoDB and node instance running locally.
If that's the case, I would recommend using environment variables for development and production to automatically configure which API base url is being used.

How to strapi + react fullstack app on one server?

I want set up a fullstack app with strapi and react. All tutorials i've seen say to deploy frontend on netlify and backend to something like heroku. Is there a posibility to deploy full app at one hosting?
I mean user entering website will get react app and backend will be running at onother port on the same hosing
You can host both the front end(react) and backend(strapi) on heroku.
they can be hosted as two different individual apps running on different dynos and they can even be hosted as a single app together.
see this answer:
How to deploy Strapi backend and ReactJS frontend to a single Heroku app
You definitely can deploy both on the same server, the question is whether you should do that.
What if your system has another client, like mobile app? Or what if you have more than one API server, and several databases (e.g. mongo and redis)? You don't want to put all of them on a single server, do you? By deploying them separately you can benefit from horizontal scaling, i.e. you upgrade your hosting plan on particular server whenever it needs more resources, without affecting another nodes. Divide and rule!
If you still want to deploy React and back-end on the same server, the better place for that would be something like DigitalOcean. On single droplet you can place as many servers as you want and configure them to launch on different ports.

Resources