Why You Should Consider NodeJS Over PHP For Your New Startup

NodeJS or PHP for your next startup

JavaScript and PHP are the most popular scripting languages for web development. Even though both languages can solve significant complexity in web development, they are built on different environments and architectures. 

There are numerous ways to develop a website; however, choosing the right platform is very important to meet business needs and scale fast. You will also find many benefits and drawbacks for any platform. Like other comparisons between programming languages, it’s a debate in the development community about which one is the best: Node.js or PHP.

If you are planning for a startup and are confused about which platform to choose, then you are at the right place. Here, we will briefly discuss both platforms and explain the top 5 reasons you should consider Node.js over PHP for your next startup.

Let’s get started!

What is Node.js?

Shockingly, a few web sources notice Node.js as the JavaScript programming language (JS) framework, which raises little confusion among current and potential users. So let’s clear this confusion: Node.js is neither a programming language nor a JavaScript framework.

Node.js is an environment where you can use JavaScript to run as a server-side language. This means that one can apply their existing JS knowledge to build server-side apps.

Node.js is an open-source, cross-platform, single-threaded runtime environment to develop quick and versatile server-side and networking applications. It comprises an event-driven, non-blocking I/O design and works on the Google V8 JavaScript runtime engine. 

NodeJS is easy to understand and optimize as well. Since it uses the mighty, battle-tested V8 JS engine, you no longer need to worry about memory consumption by dangling-pointers.

Node, however, runs on a single thread. In order to use all the CPU threads, you’ll have to do some extra steps and use the “cluster” module. This is not required with modern NodeJS frameworks as they handle this internally.

The most important part- you can reuse existing business logic on both frontend and backend. This saves time, money and reduces time to market.

Who uses NodeJS?

You might be surprised to know that since inception in 2009, NodeJS has been used by some of the biggest corporations. And they have been using it since its beta phase. It’s that good, really.

A few of them are:

  • Twitter- for building TwitterLite, their light-weight mobile website
  • LinkedIn- for building the backend for their mobile app
  • Netflix- for some of their high-scaling services in backend
  • PayPal- for quite a lot of trafficked services like account overview
  • eBay- a thin web-client that that talks to a pool of backend services
  • Uber- One of the first companies to deploy Node in production
  • Walmart-  Produced a whole framework – “hapi” for internal uses and then open-sourced it
  • Trello- Complete backend is written in NodeJS for scalable and high-performance services

What is PHP?

PHP means Hypertext Preprocessor (a recursive short form), which initially meant Personal Home Pages. PHP is an open-source, object-oriented, and server-side scripting language. PHP and MySQL combination have been in use for almost 2 decades now and it’s still going strong.

Most PHP environments utilize the Zend engine, which converts PHP to machine code for execution. There are many other interpreters now, some more performant than Zend. For example, Facebook uses their in-house built VM for executing PHP code. It’s called HipHop Virtual Machine or HHVM.

Who uses PHP?

Almost everyone. Yes, you read that right.  Particularly WordPress is used by almost 40% of the live websites on the whole Internet. With modern frameworks like Laravel and its ecosystem, we believe that PHP is here to stay for many more years.

The main users of PHP are:Let’s see which industry utilizes PHP:

  • Facebook- Started as PHP+MySQL stack. Moved to other languages after some time. Some of the most crucial services are still written in PHP.
  • Wikipedia- Whole MediaWiki software is written in PHP + MySQL
  • Tumblr- Complete backend is written in PHP
  • Slack- Started as a PHP shop, moved to other platforms later. Still uses PHP for some important parts.
  • Etsy- Complete backend is written in PHP
  • Mailchimp- A lot of crucial services are written in PHP

Comparing NodeJs and PHP

Asynchronous v/s. Synchronous

NodeJS is an asynchronous runtime environment. This means that it can handle a lot of incoming requests without waiting for existing ones to complete. This does NOT mean that you’ll have infinite scalability with Node. In fact, the performance will degrade if you do not use multiple Node processes and utilize all the CPU resources, since one thread can handle only so many requests at once.

PHP is inherently synchronous. Which means that it’ll utilize all the CPU resources implicitly, but at the same time it will cater to requests one-by-one. There have been many efforts to bring asynchronous environments to PHP but none of them have proved themselves in production. Even if you use asynchronous PHP frameworks, you’ll have to learn special syntax to build apps on them.

The Ecosystem

You need an ecosystem to win hearts, be it developers or consumers (looking at you, Apple).

Developer community at large considered the PHP ecosystem to be very old but unstable. And they have every reason to believe so. With 100s of PHP frameworks, spread across multiple PHP versions, developers are often confused which framework to use. These frameworks are not maintained and are abandoned quickly. You can even completely skip using a framework and embed PHP in HTML pages!

NodeJS on the other hand, has a healthy community. Although it also has 100s of frameworks, there are a few like Express, Hapi and Sails which are actively maintained and used by many developers. NPM registry is god-send for Node developers. Historically, PHP always had issues with packages. Composer has solved most of them, but it’s nowhere close to the NPM ecosystem.

Ease of development

Historically, JavaScript is one of the easiest programming languages. Combined with the power of NodeJS, it makes web-services and backend systems much easier to build. You can even share business logic between frontend and backend. Want a consistent way to convert dates across the stack? JavaScript has got you covered.

PHP is also very easy to learn and can be used to build amazing backend systems. But, it can’t share logic with the frontend. So, you’ll have to maintain two different code-bases which may essentially do the same thing.

Since both languages do not support types, it’s very easy to shoot yourself in the foot with them. For instance, you can reuse a boolean variable to act like an integer. Thanks to TypeScript, one can employ full static type checks and enjoy the benefits of compiled languages like Java. The code is compiled to JS and then executed.

PHP has also introduced the concept of type checking, but it’s not as good as TypeScript since it’s not compiled.

Ease of Deployment

You can’t contest with PHP on this one. Since PHP is everywhere, it’s extremely easy to find a cheap PHP-MySQL host and deploy your application. There’s a catch, however. Most modern PHP frameworks like Laravel are not compatible with these cheap shared-hosting servers. Which means that you’ll have to customize your base framework methods/directories to make it work. This is not generally acceptable, but then for smaller, development projects, it can work.

NodeJS can act as a server, but it’s not recommended though. One should always use a reverse-proxy like Nginx or HAProxy in front of a NodeJS server to handle requests. Given this fact, it’s a bit hard to deploy NodeJS apps in a production ready environment.

To ease deployment in both the cases, it is recommended to use tools like Ansible or Docker to automate the deployment process.

Building modern web-apps

By “Modern web-apps” we mean web applications with real time functionality using web-sockets and server-side events.

NodeJS clearly wins here because it’s by-default asynchronous in nature. This means that opening multiple web-socket connections is very easy and lightweight on the server. Socket.IO is one such amazing library to handle web socket connections with minimum code.

PHP, as we saw earlier, is synchronous in nature. This means that opening web-socket connections is resource heavy. Plus, you have to use special async servers with specialized connection pools to even use websockets in PHP. This results in more external dependencies as well.

So, why should you pick Node.js for your next project?

Let’s summarize our discussion in few points below-

  • NodeJS is asynchronous in nature and hence it can handle more connections than PHP with similar resources.
  • NodeJS has a better package manager and better community as well.
  • Thanks to JS, NodeJS is easier to develop on and with TypeScript, it enjoys benefits of compiled languages with less run-time exceptions.
  • With NodeJS, developers can share business logic between frontend and backend because both are built using JavaScript.
  • PHP has cheaper and quicker hosting solutions but they are limited when it comes to modern PHP frameworks like Laravel.
  • NodeJS should be used with a reverse-proxy server, which adds complexity in deployment. Docker and Ansible are recommended tools for both Node and PHP.
  • Building a modern web application with web-sockets to real-time communication is easier with Node than PHP.

Based on the above summary, we can say that Node is a better choice for building modern, real-time applications and web services. But we can’t completely ignore PHP as it is a more stable choice of the two and with frameworks like Laravel, PHP has gotten a very good ecosystem as well.

Looking to hire NodeJS developers on rent? Reach out to us on hello@citrusleaf.in and we will provide you with the top talent.