Node.js isn't completely new, but it's quite recent, not just in term of code, but also as an idea.
Let's me explain...
Front-end vs Back-end development
Code running on the server is managed by the server itself, so provided you have a server able to run your language of choice, you can run whatever you'd like! You could write your own new language and provided your server supported it, it would run properly on your website.
But the front-end code runs in the browser of your clients, which are Google Chrome, Mozilla Firefox, Microsoft Edge or Internet Explorer, Safari, Opera, etc...
Not only would a new language require to be supported by each of the browsers used by your visitors, but your visitors would need to upgrade their browser which isn't always something they can do (perhaps due to corporate policy or outdated apps).
This means that a Full-Stack developer (someone who codes both in the Front-End and the Back-End, and thus, the Full-Stack), needs to use at least two programming languages:
- Something else (often PHP) for their back-end code
A revolution in the web server
You see, between the Front-End and the Back-end sits the web server, the two most popular being Apache and Nginx (pronounced "Engine X").
If you've seen your FaceBook feed update when someone types a comment, that's AJAX.
The problem is that when the back-end is hosted by Apache, the AJAX requests, which are Asynchronous in nature, are handled by a web server which is synchronous in nature: it blocks until a call is resolved.
Node.js solves that by being completely asynchronous (and non-blocking) by nature. That's what Node.js bring to the table: a revolution in how web requests are made.
In a nutsell That's the same difference between calling and texting a friend. When you call a friend, the only way to convey information back and forth with him is if you are both on the line at the same time: your ability to send him a message is blocked by his inability to answer you at that very moment.
With texting, you can send him a message, forget about it, and eventually, get a response. You are not glued to your phone to deliver him a message.
Nginx vs Node.js
I mentionned NginX above, and like Node.js, it is non-blocking but Nginx performs the asynchronous management at the server level, while Node.js does it at the application level, and that's rather fondamental.
When you make a request to an Nginx server, your process still waits for NginX to answer, but Nginx is able to reassing the worker you used until a response is ready. In otherword, if you request a report which takes 60 seconds to run, you will wait for the 60 seconds, but Nginx will not block one of it's workers for that process, it will be able to handle more other request while you wait.
Node.js on the other hand, doesn't make you wait. It accepts your request, processes it offline while you are not waiting for it, and will call you back once it's ready.
In order of ascendance, if you ask a report which takes 60 seconds:
- Apache will make you wait on the phone, and waits on the line with you until your report is ready. Too bad if other callers are in the call queue or if you have other calls to make
- Nginx will make you wait on the phone, but will put you on hold to handle other calls until your ready is ready. Other callers are served, but do bad if you have other calls to make
- Node.js will take your message, hang up, and call you back once your report is ready. You both get to make and received other calls
So why I am not a Node.js developer yet??
But when Luke left to found his own Node.js firm, we lost the internal knowledge to keep going but I kept dreaming of the day I would also code in Node.js.
Will Node.js take over PHP then?
And bring us to the next problem with Node.js: it's not as mature yet as PHP is. Node.js is improving with more and more Frameworks and tools, but until then it remains mainly for specialized high traffic or high capacity applications and isn't yet in the main development environment.
I believe that long term however, Node.js can be a force to reckon with and will allow to build rich very fast applications that react almost instantly.
Until then, many benchmarks that shown that overall, many PHP Frameworks (including Laraval), are able to match or beat Node.js for regular traffic volumes (even if Node.js is often able to handle higher traffic volumes).