Understanding the Node and Applications in real time

14

Since I first met CakePHP , I got used to programming with it, as it had a small learning curve and greatly speeded up development.

For my recent application, I needed the data entered by the users to be monitored in real time in terms of their quantity (a simple% of% in mysql). Researching the subject, I found the NodeJS.

Now I'm beginning to understand NodeJS and its application but I do not know if I understand it right but to what I think, if I want to make an application in real time or part of it, I have to "throw away" everything I've learned and do all again in NodeJS? I wanted to monitor data insertion in real time, but it seems that this is not possible because NodeJS would replace Apache and maybe even PHP using modules that connect to MySQL.

Everything I find is in English and, a little bit in Portuguese, is almost a translation of the English texts So here are some questions that were not clear to me:

  • NodeJS replaces Apache and I have to choose between one and the other?
  • Does NodeJS replace PHP? For example when the node itself has the connection to Mysql?
  • Is it not possible to integrate the Node with Cakephp or another framework, type Rails?
  • If I have an application already ready and want to integrate it into NodeJS, do I have to rewrite it?
  • Does NodeJS depend on Nginx? If not, is using the 2 at the same time a good output?
asked by anonymous 13.03.2014 / 15:12

4 answers

11

I've worked with PHP for many years, today I work a lot with Python, NodeJS and nginx. I have a slightly different point of view from the ones presented so far.

The Node replaces Apache and I have to choose between one and the other?

You can use the node to be the server as well, but it is not a good practice, you can integrate the node to work with other servers, including Apache.

Does Node replace php? For example when we have the connection to Mysql itself?

Node can replace PHP yes, it can connect with MySQL and other databases, just like PHP, depends on the purpose of your application and the strategy you want to adopt Node may be a more appropriate solution than PHP.

Is it possible to integrate Node with Cakephp or another framework, type Rails?

You will not be able to write a file with PHP and Javascript and process them both at the same time, but integrating them is possible, both PHP make requests to the node server and vice versa. It is also possible with Rails or Python. Today we use the company where I work a middleware server made in Python with Django integrated with distributed Node servers that do the communication part in asynchronous websocket.

If I have an application already ready and want to integrate it into Node, do I have to rewrite it?

It depends on what you want to integrate, but you probably need changes to the integration points to work with the new dependencies.

Does Node depend on Nginx? If not, is using the 2 at the same time a good way out?

It is not dependent, but nginx is a great server for working with Node, either to be part of the cache or even to work with multiple upstream nodejs, allowing load balancing on your servers.

One of the things you can do to integrate your systems is to have the nginx server giving you external access and mapping the paths that will drop into nodejs and the ones that will fall into your apache that PHP provides (if you use Apache integrated with your PHP, otherwise you can use nginx to directly access your PHP too).

So in the case of monitoring real-time COUNT , one of the interesting applications would be a websocket server on nodejs, where its users could be connected and traffic data in real time. On the server side your PHP could warn your Node every time it did an insert or remove operation on the database so that the node would replicate the COUNT value to its clients in real time.

All this operation is possible with PHP also, using Pushstream, but in the end it is so much more complicated, that it is worth adopting the node for such a solution. Even chat or games are cool to work with node, because his proposal is to be treated as events in micro blocks and not as files processed as blocks and sent to the client like PHP.

    
13.03.2014 / 16:18
6
  

Does Node replace Apache and have to choose between one and the other?

has a webserver of its own but is compatible with Apache, Lighttpd, Nginx and others.

To make it run on Apache, here's a tutorial .

  

Does Node replace php? For example when the node itself has the connection to Mysql?

Yes, Node is a server-side platform that does more or less the same role as PHP.

  

Is it possible to integrate the Node with Cakephp or another framework, type rayls?

It is not possible because Cake is written in PHP and Rails in Ruby. Node has its own ecosystem. There are several frameworks for it, such as ember.js

  

If I have an application already ready and want to integrate it into the Node, do I have to rewrite it?

It depends on how you are going to do the integration.

  

Does Node depend on Nginx? If not, would using the 2 at the same time be a good output?

They are different things, for different purposes. Node is the language, Nginx is the web server.

    
13.03.2014 / 15:34
4

1. The Node replaces Apache and I have to choose between one and the other?

Yes, but it is not mandatory. It can be run together with Apache, just listen to a different port.

2. Does Node replace php? For example when we have the connection to Mysql itself?

According to the answer to the first question, no. They can co-exist seamlessly

3. Is it possible to integrate Node with Cakephp or another framework, type rayls?

I'm not clear with PHP, but Node is able to respond to any type of request. So you basically need to implement a service that listens to a certain port and answers your PHP requests. They would be normal HTTP requests (GET, POST, etc ...).

4. If I have an application already ready and want to integrate it into Node, do I have to rewrite it?

It would not be necessary, but you would have to evaluate how the integration would be done.

5. Does Node depend on Nginx? If not, is using the 2 at the same time a good way out?

Unfortunately I can not tell you if the node depends on Nginix because I never researched it. What I can tell you is that it, Nginix, is a very lightweight server, even consuming even less memory than Apache. It would not hurt to use both at the same time.

If I find something about it I'll edit my answer.

Just to enrich your experience with Node, I'll leave this link with some extensions that will help you a lot.

    
13.03.2014 / 15:35
0
  

Is it possible to integrate the Node with Cakephp or another framework, type rayls?

It is entirely possible to use CakePhp with Node. I recently implemented a notification system and a chat (both realtime) between two users (using NodeJs) on a system made in CakePhp. I use CakePhp to write messages and notifications in DB and Node to notify in realtime.

    
27.01.2017 / 14:37