Express Node.js Backend Running on Fargate - node.js

I'm running an Express Node.JS app on ECS Fargate behind an ELB. The issue I'm having is that static files (css, js, images) aren't loading. Can anyone offer me some possible solutions?
In addition, I noticed that I can only access the root path of my express app through the ELB. When I do attempt to access a different path, I receive a 503 error. Is there someway I can address this?
Thank you!
I ensured my express.static middleware was set to the public folder and that my public folder was at the same level as the express file.

Related

Deploy ReactJS Build folder WITH NodeJS + ExpressJS to hosting provider (Apache server) through FileZilla

I have a simple React app with API fetching to my NodeJS + ExpressJS server.
The structure is as followed:
/build (React app)
/server/server.js
When i deploy the site, i just drag and drop all the files within my build folder to my public_html folder that i access through fileZilla.
My hosting provider is www.domain.com.
I have never had to serve backend files before, so i have no idea on how to serve/deploy the Express server through my domain.com hosting provider.
The main task for my Express server and NodeJS backend is fetching data from a MySQL database hosted on AWS, so its just a simple queries.
At this moment my React front-end uses axios to fetch like this:
axios.get("http://localhost:4000/<myApi>")
I can assume that since the main task of the express server is to listen on a port for incoming requests, i would need my www..com to listen for incoming requests. But how to solve this i do not know.
Please help a newbie :)
If there is some missing information, please feel free to comment what else you would like to know.
For now i have just deployed my front-end without any interaction with my server since i have no idea on how to host a server on a server if that makes sence?
The apache server is provided through www.domain.com as i explained, and i use FileZilla to deploy my React build folder to the public_html folder on FileZilla.
I have searched a ton. but mainly people explain through Heroku, netlify and etc, so i cant find a perfect match for my problem anywhere.

Running Mongo Node Angular on same server

Can I / Should I host Angular, Node-express and Mongo on same server, say localhost:3000 or somehosting.com/server-address?
Also is it a good practice?
I've seen Angular and Node running on same server, but what about adding mongo too?
like everything equivalent to
mongodb://localhost:3000/db
ng serve --port 3000
server listen(3000)
Thanks
As you have not mentioned for what purpose - the answer will be depending on the purpose and context. If you are learning, then running webserver, database and serving Angular static files , all from the same server is not an issue. However, if you are going to have live web app, even with less or moderate traffic, then you must run database on its own server, and the webserver and static Angular files from one server. Of course, for SPAs that expect lot of traffic and real use, it is better to serve your static Angular files from a CDN or storage service like AWS S3, and web and database servers separately.
Happy learning!
It is best practice to keep the databases(stateful) in different servers then the applications(stateless) unless it is just for testing...

Deploying React native app with node server to the store

I feel like I have exhausted all possible searches and documentation trying to figure this out. I have a React native app which runs perfectly locally with a node server with websockets, I will like to know steps on how I could deploy this app to the store. I understand the server has to be hosted for example on heroku, but the workaround of the whole process from local server to heroku, then AppStore still confuses me. I will appreciate any suggestions, or clarification on how I could achieve this(deploying server and connecting to React native). Thanks
Host your Node.js server;
Use the remote server's endpoint on the app;
This can be useful to have a dynamic endpoint (dev and production env):
const endpoint = __DEV__ ? 'http://localhost:8080' : 'https://myServer/';
After your app get published on App Store it will communicate with remote server.

Ubuntu Node js With Socket io Not allowing client to connect

I'm trying to get the socket.io working in Ubuntu using Nodejs.
Tried to disable the firewall, open ports 3000,4000.
I'm using PM2.
Deployed In DigitalOcean
Now in my Angular client App I get this error
Also I have core errors setup in my node js
client:1 Access to XMLHttpRequest at 'mydomain.com/socket.io/?EIO=3&transport=polling&t=N4_SuJm'
'Access-Control-Allow-Origin' header is present on the requested resource.
Although I did publish the same code in AWS ElasticBeanstalk and it worked just fine so nothing wrong with the code
UPDATE
I managed to solve the issue
UPDATE
I managed to solve the issue
For future reference
the problem was that the socketio client removes the path from the url
that is given when connecting exampledomin.com/api is the correct path
for socketio in node js but the socket io client removes the /api and
points it to /socketio so i added a Location in the nginx config to
point to the server hope this will help someone down the road

Hosting a webapp with a ReactJs frontend and ExpressJs backend

The frontend is a React SPA and the backend is NodeJs app that exposes an API. The frontend queries the API for data from time to time but other than that it is fairly independent. What is the best way to host an app like this? Should I include the build folder in the NodeJs app and have the express server serve the static contents from a route? Or should I host both separately, set up a Nginx server for the React app on something like DO? I will host the backend on something like Heroku or Google App Engine. So considering this, what is the ideal solution? What are the pros and cons of either approach?
In case of production, include build folder in the nodejs app. Performance increase in case production. You can refer react docs for details.
In case of development, host it separately, so its easier to work on it.

Resources