Using ReactJs with express and Socket.io - node.js

So I'm building my first single page app with react, and it's going well so far.
I'm using create-react-app to build and run the app I'm building, and now I arrived to the part which I need to interact with a Server side.
so when I tried to find the way to build an express with socket.io server, I couldn't find how to do it so the create-react-app will build it to.
so my questions is this -
How can I create a server side and compile it throug the create-react-app?
or on the other hand, how can I integrate socket.io and react app on create-react-app?
thanks,
Eilon

Related

Websocket not working in React.Js production build

I created a react App which talks to a node back-end. Everything works fine in development mode. The connection between the front-end and back-end is made through websocket.
Most interesting thing is, that after doing yarn build to create the production build of the app, all the pages work fine. The only thing is that, the page that integrates connection with the back-end is returning error when I inspected it in the browser. I am using Apache Server to run the build version of the app on localhost.
I am using Apache server since python server throws errors on page refresh.
Below is the screenshot. As you can see, node server command, return the expected response from the backend app. The structure of the app is also shown; revealing the relationship between the front-end (smartschool and smartresult) and back-end (smartapi). Only the smartresult makes the request to back-end. How do I resolve this connection problem? Any help will be appreciated. Thank you.

How to run Node js in React Native App after generating the Apk?

I am currently using Express and Node js as my backend for my react native app. Right now i need to run my node js server if i want my react app to access the backend and my REST API. I wanted to know how can i run node js in my react app after i extract the apk file. How will others be able to use my app on their networks. How to run the node js server remotely.
Sounds like you misunderstand a few concepts:
You don't run the api server from the client. The server must already be running if you want to access it from the client
If you want others to use this api with their clients, you should be running your api server in a public env (instead, or along with your dev env) so it will be accessible to clients from around the world

How to share the server code to electron app?

I am developing a postman like application with some added features. For the frontend, I am using Angular 10, and for the backend, I am using node with fastify.js and for the database, I am using MongoDB via Atlassian MongoDB hosting.
Right now, I have set-up the electron app and using the same frontend code. It's working fine if I use the API(I have hosted my node server on ec2). I want to run this app without an internet connection. for that, I set up the node server in electron. The node server is working fine if I run it in the main electron process.
My electron application setup:
I am running a node server in the electron app on port 5000.
when electron app starts it will start the server.
To make sure everything is working fine I used a postman to access the node server running from the electron process.
In postman, if I am hitting on http://localhost:5000/ while the electron app is running I am getting a response from the node server running in the electron.
If I use localhost:5000 as the base URL and hit the API from frontend in electron it's working and I am getting a response. I checked the electron console network tab, Request is going to the http://localhost:5000/.
Now I want this app to run without the Internet. neDB is the most suggested DB for electron and it provides the same query syntax as MongoDB. Also, I found out library mongoose-nedb. Using that library I can use mongoose with neDB. So, If I use that library I don't need to change my node code and can use mongoose with neDB instead of MongoDB. So, I set-up my app with neDB and mongoose-neDB. for testing, I again use the postman as well as electron frontend. But now I am not getting any response.
I tried LinvoDB as well. same result.
Is this happening because I am using neDB outside the electron browser context?
Can you suggest some solution so that I don't need to rewrite the node server in the electron app?
Is this approach proper? any suggestion?
Ref:
I am using this boilerplate for the electron app: https://github.com/maximegris/angular-electron (I am putting my node code in root and importing it in main.ts)
mongoose-neDB: https://github.com/aerys/mongoose-nedb
neDB: https://github.com/louischatriot/nedb
LinvoDB: https://github.com/aerys/linvodb3
mongoose-LinvoDB: https://github.com/aerys/mongoose-linvodb3

Deploying create-react-app express api to heroku

I have an app that uses a React/Redux client (generated by create-react-app) and it communicates with a Node/Express api. When I run this during development, it works perfectly.
I just deployed to Heroku for the first time however, and only the client side of my app is working. I get error messages in the console that the api routes return a 404.
Any ideas on how to solve this? I think it must be something simple like adding a script to package.json.
UPDATE: SOLVED: The issue was a freaking Procfile. Make sure to include a Procfile and write web: node server inside.

How to make a ember app talk to an express api in production with Nqinx

Im working in and Ember App that use a API build with Express js, for development i just run my express api and then run ember server --proxy http://localhost:8000
for example i could be whatever port, so now i have to deploy that to a production environment that im working on, i planing to use nginx, but what i do not know and can't fine is that once a build my ember app for PROD and make nginx serve this files, how do i do to make the ember app knows where to talk to the api.
You specify the host property for your application adapter (which you will need to generate): http://emberjs.com/api/data/classes/DS.JSONAPIAdapter.html#property_host

Resources