Understanding Node and Applications in Real-Time

Asked

Viewed 1,700 times

14

Since I met the Cakephp I got used to programming with him, because I had a small learning curve and very fast development.

For my recent application, I needed the data entered by users to be monitored in real time in relation to their amount (a simple COUNT mysql). Searching on the subject, I found Nodejs.

Now I’m beginning to understand Nodejs and its application but I don’t know if I got it right but it seems to me, if I want to make a real-time application or part of it, I have to "throw away" everything I’ve learned and do it all again at Nodejs? I just wanted to monitor the insertion of data 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.

All I find is in English and, the little part in Portuguese, is practically a translation of the texts in English So here are some questions that I didn’t understand:

  • Nodejs replaces Apache and I have to choose between one and the other?
  • Does Nodejs replace PHP? For example when by Node itself we have the Mysql connection?
  • Node integration with Cakephp or another Rails-like framework is not possible?
  • If I have an application ready and want to integrate it into Nodejs, I have to rewrite it?
  • Does Nodejs depend on Nginx? If not, using 2 at the same time is a good output?

4 answers

11


I have worked many years with PHP, today I work a lot with Python, Nodejs and Nginx. I have a slightly different point of view from those presented so far.

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

You can use Node to be the server too, but it is not a good practice, it is possible to integrate Node to work with other servers, including Apache.

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

Node can replace PHP yes, can connect with Mysql and other databases, such as PHP, depends on the purpose of your application and the strategy you want to adopt Node can be a more appropriate solution than PHP.

Node integration with Cakephp or another Rails-like framework is not possible?

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

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

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

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

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

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

So in case you monitor a COUNT In real time, one of the interesting applications would be a nodejs websocket server, 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 does an insertion or deletion operation in the database so that Node replicates the value of COUNT for your customers in real time.

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

  • vc could indicate me a text or site where I can see an example of Count like the one you mentioned above?

  • One of the ways I usually communicate between different languages is by using HTTP protocol (as it is quite simple and most support). Take a look at this site: http://resthooks.org/ the concept of Hooks applies to any communication layer whether between applications or client. But as for the client you have no way to turn the browser into an HTTP server waiting for a request, we use websocket or longpooling to request the server to the client when the hook on the server is triggered by another internal application. I have no opensource projects to demonstrate.

6

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

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

To make it run over the Apache, here’s a tutorial.

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

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

Node integration with Cakephp or other rayls-like framework is not possible?

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 ready and want to integrate it into Node, I have to rewrite it?

It depends on how you do the integration.

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

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

  • o Node é uma linguagem server-side Actually the language is Javascript. Otherwise, +1.

  • @Renan The above statement is correct because the Node runs on the server, no matter how javascript.

  • @Edgarmunizberlinck Node.js (which is the way to write the name of technology) is not a language.

  • @Renan sorry, now I understand what you meant. In fact Node.js is not a language.

  • There are controversies. Although it uses a Javascript engine (V8), there are things that differentiate the JS node from the browser. I consider it another language.

4

1. 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 listening to a different port.

2. Node replaces php? For example when by Node itself we have the Mysql connection?

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

3. Node integration with Cakephp or other rayls-like framework is not possible?

I’m not cut out for PHP, but Node is able to respond to any type of request. Then you would basically need to implement a service that listens to a given port and meets your PHP requests. Would be normal HTTP requests (GET, POST, etc...).

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

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

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

Unfortunately, I can’t tell you if the Ode depends on Nginix because I never looked into it. What I can tell you is that he, Nginix, is a very light server, and even consumes less memory than Apache. I would have no problem using both at the same time.

If I find something on the subject I edit my reply.

Just to enrich your experience with the Node, link with some extensions that will help you a lot.

  • 1

    I don’t know much about it either, but I’ve heard of using Nginx in front of Node to handle cache.

0

Node integration with Cakephp or other rayls-like framework is not possible?

It is fully possible to use Cakephp with Node. I recently implemented a notification system and a chat (both Altime) between two users (using Nodejs) in a system made in Cakephp. I use Cakephp to record messages and notifications to DB and Node to notify in Altime.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.