Should I use a separate Socket.IO server or not? - node.js

I'm currently working on a Node.JS application which needs to be highly scalable for use in a particularly popular website.
Currently, the Node.JS and Socket.IO server is running as one application meaning to deploy a new release I just restart the server.
I've had suggestions to make the Socket.IO server separate to the Node.JS app running the site but feel as though this could make keeping the Javascript from the web server and Socket.IO server in sync tricky.
What should I do?

Related

Deploy Node.js on tomcat

I have developed an application using Angular, Node/Express and MySQL. I have deployed my Angular application on the tomcat server, which is connected to some 10 PCs. However, I want to deploy my backend i.e, Node.js/Express.js on the same server as well since my app is totally dependent on the backend. How can I do that? I read online that one cannot deploy node.js on tomcat as both are separate servers. Do I have to install Node.js/MySQL separately on the same server? Isn't there any security threat linked to hosting the front-end and the back-end on the same server machine?
I would really appreciate if someone could clear my mind regarding this.
It's true that Tomcat and nodejs are separate web server programs, and you cannot run one within the other. You can run them both on the same machine, but they must use different ports.
You can use a reverse proxy server (nginx) to project the illusion to your end users that your Tomcat and nodejs apps run on the same server and port. Explaining how to do that is far beyond the scope of a SO answer.
You can share a database server (MySql) between the Java applications running on Tomcat and the Javascript.
There is no inherent security risk in hosting your front-end and back-end code on the same origin server. In fact, there are security advantages, because you can set up restrictive CORS rules.

Optimizing Node and socket.io on NGINX Proxy

I'm attempting to scale a Node.js application but am a little confused on one piece of it. I moved all my static files to the gateway server running NGINX, and it routes them accordingly. Now looking at the waterfall diagram in Chrome's dev tools, I notice a full second of wait time to access the socket.io javascript file. I'm assuming that is because this is still being accessed from the application server, not the web server. My question is, can I move this file to the web server to have it load faster? It's an npm module so it seems a little fishy to me, like it needs some sort of interaction with the application server to initialize the connection or something. Or am I thinking about this all wrong? Thanks!

How can I deploy a client-side ReactJS + Node.js application on Ubuntu Linux?

I have a client-side ReactJS and Node.js Express application running on the local machine at the moment. I would like to now deploy the client-side application to an Ubuntu Linux server, where the back-end, database and REST API, is already running.
What's the way to go about doing so? I did the research but all seem to have both front-end and back-end, and do not fit the criteria that I am looking for. So I was lost and reached out here. Thank you

node.js socket.io apache server

I have some sort of noob question regarding to node.js and socket.io. These two guys are usually needed to use websockets for server to browser communication. Once that my project gets done, do I have to upload my php files to my apache server. Now my question is do I have also to upload my node_modules directory to my apache server? along with socket.io directory?
In order to run your node.js process you need to have ability to execute own applications on server. Classic virtual server does not allow of such functionality. There is virtual server hosting for node.js specifically, check out nodejitsu, heroku or any other.
You can run node.js as web platform by it self, without of use of any apache, that will make your life much easier. But if you still need apache and PHP, then you need to consider proxying from apache to your node.js process. This still can be tricky as proxying WebSockets is not straight forward.
If you have access to Apache settings, then you can enable proxying for HTTP/HTTPS, read this: http://ronenagranat.blogspot.co.uk/2011/02/apache2-reverse-proxy-for-nodejs.html
For WebSockets, there is not much data available but here is possible solution: http://blog.cafarelli.fr/post/2013/04/26/Backporting-Apache-support-for-websockets-reverse-proxy-(aka-getting-GateOne-to-work-behind-Apache)
Although if you have own server and have ability to choose between web platform, I would recommend to look into nginx, as it has support for WebSockets proxying (might require module and nginx recompiling).

confusion in bootstrapping my application in backbonejs

I have a working application in codeigniter phil sturgeon REST API with backbone.js, underscore.js and require.js
Ineed to use mongodb and node.js in the backend. I have build a working REST API for the same. Now i am clueless as to how to migrate my whole project to work with this API. I use XAMPP on windows to serve apache. So since now i don't need to use xamp, how do i determine the structure of file system?
what files will go there? how do i bootstrap my application?
Node.js comes with an application server.
You need to run your application server at a certain port (e.g. localhost:3000).
There are multiple ways to deal this:
Application Server is also the Web server.
That means your application server at port 80. That's not really an optimal solution as application servers are not ideal for static assets. I think there are some security issues too but need to read on that.
Setup a web server and forward requests to application server
Here you will setup a web server. apache is a web server but for nginx is optimal for node.js applications. So you run your web server on port 80 and forward all requests to your application server port (e.g. 3000) . You setup nginx in a way so that for static assets (images, javascripts, css etc.) it doesn't bother application server but just serve the files directly from the file system.
Setup a proxy server in node.js
Take a look at Bounce Not sure how it performs in a production setup but the reviews are good. But it suffers from slowness in serving static asset.

Resources