Enable to get socket.io file on client - javascript

I using a angulajs as frontend and node.js REST API as backend both our on different server. I want to use socket.io, but enable to get socket.io.js file on client from the node.js server i am using
<script src="http://localhost:3000/node_modules/socket.io/socket.js"></script>
to get the socket.io file.
Error:
GET "localhost:3000/node_modules/socket.io/socket.js "

I highly recommend taking a look at this library:
https://github.com/btford/angular-socket-io
This way you can easily integrate socket.io with Angular for client side

Related

Deploying a node.js frontend and spring boot backend as a self contained app locally

I have a web app that has a separate spring boot backend and a nodejs frontend.
is it possible to make them both run on the same bundle, like building a singe executable? or do i need a stand alone service for each? Both are having their own jenkins pipelines and git repositories.
My backend server is just a API that provides the frontend with simple data via REST services. If it is possible what would be the way to do it?
A nodejs is a backend technology, not frontend.
You can use a nodejs as an entry point to a spring boot application but it is a code running on the server side. So nodejs is not just a list of static files as it happens for a real front end developed in react, angular or vue (or vanilla javascript). It has also an engine to run the code.
So is not possible to run nodejs server using files that are compressed in the executable jar. Instead is possible to put a real front end application (react, angular...) adding static files in the directory /resources/static
It was maybe a little missleading. My frontend is an app runing on node.js server and may backend is a java app runing on spring boot server. They are communicating on localhost via Rest.
I want to create a single entry point that starts the node.js server (I call this unit frontend) and the spring boot server ("backend") at the same time. So it feels like a self contained system.Currently the spring boot app is delivered as windows executable.

Can I run my Node.js/Express backend and React.js frontend together in the same file structure?

I am making a web app that uses a Node.js/Express backend and a React.js Frontend. Right now I have my Node.js code that validities login/registration credentials in a separate folder running on localhost:5000 while my React.js frontend login/registration form code is running on localhost:3000.
My question is would it be easier to put both my frontend and backend code into one file structure so I don't have to send the data from my form to my backend running on another domain so for example both my Node.js and React.js code would be running on localhost:3000 and would just send the form information to the Node.js files that validate the user credentials instead of having to use a fetch method to send my form data to the backend. Is this even possible?
Yes, it is possible, you can use Express to serve your static files (frontend ReactJS) and also your backend routes. Take the following Github repository as an example.
https://github.com/Bikranshu/express-react-boilerplate
That is possible, A monolithic architecture with express and reactjs (https://medium.com/#sesitamakloe/easy-express-react-monolith-chapter-1-a1567c6ff483)

How to create a nodejs websocket client

I'm working on a project where I need to have multiple node clients connect to a node server via websockets. The clients will send files to the server and the server will immediately distribute that file to all connected clients.
The problem I'm running into is connecting as a client in node. The built in ws module seems to only support server use. I've also tried the npm websocket client which allows me to use node as a client but I seem to only be able to send binary data without any other information like the filename, etc. using the sendBytes method.
Thanks for any suggestions.
Checkout the delivery package of npm.
It provides bi-directional file tranfer for node.js over socket.io.
https://www.npmjs.com/package/delivery

Consume Rest API on same ip but different port

Let's suppose a backend application, which exposes some Rest API, running on a Jetty webserver at address 192.168.1.10:8889.
I would like to have a frontend application (html/javascript only, on a apache2 webserver) running at the same IP but on a different port (e.g. 8000), which should consume the API exposed by the backend application.
How can i get this architecture working without get into "No 'Access-Control-Allow-Origin'" error?
I think that you should install a nginx proxy.
configure it as a reverse proxy you can see documentation here :
https://www.nginx.com/resources/admin-guide/reverse-proxy/
You can search on google for more specific documentation on what you want to do.

Node.js serve as a backend server for frontend app

I want to use Node.js run as a back-end server to serve front-end socket.io request.
The samples I found, seems can only run pages from Node.js server.
<script src="/socket.io/socket.io.js"></script>
The above js include is served by Node.js, how to include it if the front-end is a different application (e.g. PHP or static pages) ? Do I need to include all the dependent socket.io js libraries to make it work?
I'm currrently running apache/php alongside node.js/socket.io
If this is what you're trying to do, you can do it by serving socket.io on a different port than what apache is serving on (assumed 80).
In node.js, initialize the socket.io listener on a port 8080 for example:
var io = require('socket.io').listen(8080);
I believe, by default, socket.io will also serve its static client side files conveniently for you, such that in you html, you can:
<script src="http://yourhost:8080/socket.io/socket.io.js"></script>
Hope that helps.
It all depends on your server configuration. You may choose a path to Node.js backend that is not used by any other resource, and configure your web-server to serve everything else.
E.g. for Apache I used ProxyPass directive to enable connections to a local Node.js on a different port (to bypass local port restrictions), though may be not an option for your purposes:
ProxyPass /help/server/ http://localhost:8002/ connectiontimeout=1500ms

Categories

Resources