Tech Watch

Every afternoon at 2PM our students participate in something called Tech Watch.

This consists of a 5 minute presentation done by each individual student on a hot topic that is currently trending in the tech world. As the tech sector grows and the variation of topics expands, we want to share our students opinions on these topics.

This week we begin with Rayan, she writes about the advantages and disadvantages of using PHP and Node.js. She begins by comparing them technically and ends with her own opinions on the differences between the two.

Question:
In our current project at Codi we are using Node.js even though we have WordPress which we can also use. Does anyone know why we use Node.js instead?

Introduction & Definition:
PHP and Node.js are both powerful back-ends for dynamic websites. They both fall under the same category, yet their features are quite distinct.

Node.js is a JavaScript programming language that runs on the server. It is used to make webpages more interactive and dynamic. The emergence of Node.js in 2009 made it possible to perform asynchronous coding with JavaScript.

Node.js and PHP are both server-side scripting languages. One is not better than the other, the project needs should determine which one would be more preferable to use.

Similarities:
1-Both PHP and Node.js are interpreted languages.
2-Both are used to build websites and both are run on server-side (different reasons make one more preferable over the other).

Differences:
1-Run-time Environments: PHP has a ready to install feature to use on the server-side, Node.js is a run-time environment for JavaScript on the server-side.
2-Complexity of use: PHP is much simpler to use compared to Node.js, Node.js is not complex to use but requires more lines of code and a basic understanding of closures and callback functions.
3- PHP uses a multi-threaded blocking I/O to carry out multiple tasks to run in parallel with each other but Node.js uses an event-driven non-blocking I/O execution model.
4-Execution: PHP is synchronous and Node.js is asynchronous.
5-Execution Speed: PHP is slower than Node.js.
6-Web Server: PHP runs on the Apache web server and Node.js uses the NPM package, this package does not require a web server.
7-Package Manager: Composer package manager is widely used in PHP and Node.js uses NPM.

Different reasons can make one more preferable than the other, Node.js is more extensive and faster compared to PHP which may make it a more viable choice.
However, some programmers prefer PHP because it is easier to pick up than Node.js and it features an integrated database.

---> using PHP or Node.js depends completely on the nature of your project<---

When to use PHP?
1-Centralized Server: In case we do not plan on scaling our application across multiple servers we can use LAMP.
2-Portability: The cheap costs of web hosting and the availability of the servers for PHP is second to none, PHP can run on almost any platform that has Apache, IIS and has a supported database system installed.
This makes PHP applications portable and easy to deploy.
The CMS, such as WordPress, Drupal or Joomla, makes it easier to create websites and work on almost every web host. WordPress powers 30% of the web.

When to use Node.js?
1-Same Language across the Stack: Node.js would be the correct choice to use if your project involves software stacks such as MEAN stack (MongoDB, ExpressJs, AngularJs.), dynamic single page applications, server side technologies and Front end technologies like Angular Js, Backbone.Js or React Js. This makes it easier using all the same language (JavaScript).
2-Real-time Data: Node.js is great for applications that require real time data, but using Node.js for financial applications such as JavaScript itself is not reliable when it comes to numbers as everything is integer or float and not much separation is done between the types.
3-Speed: Node.js is faster than PHP when it comes to execution speed. Speed is what you require for your application, such as a browser based multiplayer game or a chat application. For speed, Node.js is a better choice than PHP.