NodeJS and PHP are basically two of the main contenders when it comes to selecting a web framework to implement your API on. Since NodeJS is based on Javascript it basically has a long history as a language but it’s still fairly new as a framework. The work done in the engine is very comparable and keeps improving over the years. Today I’m going to cover if NodeJS can really replace PHP which is one of the goto solutions for most companies when setting up an API server.
Before I go into the details and start covering my experience with both has been pretty extensive and I’ve basically used them since inception. Based on that I can tell you with certainty that both have advantages and disadvantages when selecting the correct framework and the decision depends a lot on what you want to accomplish. In order to overcome this and give you an answer I’m going to talk about the different ways each of those frameworks is optimal compared to the other and let you decide if NodeJS can really replace PHP.
Does NodeJS Have Good Frameworks Like PHP
Before diving and going into the language specifics which I think will probably end up in a tie and very opinionated I want to cover an important factor when making a decision. To me in order to know if NodeJS can replace PHP I need to also look at other things such as the community, support, availability, updates but most importantly frameworks!
As you probably already know PHP has one of the best web frameworks in the space which is called Laravel. Essentially the framework complements greatly the language and extends it to the point where it can be a core decision maker. Typically languages on their own and their standard libraries are good to get started in smaller projects but once you want to do something more serious you will probably need to use tools and functionality outside that space.
That leaves you with two options either to implement your own or use a ready one if it’s available. Luckily PHP has Laravel which in my opinion is hard to surpass easily. Since NodeJS doesn’t really have any similar frameworks but just a scarce set of libraries and smaller efforts I do not think it can be a match in this case for PHP. So in this first area I think NodeJS lacks what it takes of a good framework and you need to be prepared to do a lot of things from scratch.
Does NodeJS Have A Good Community/Support Like PHP
As I mentioned earlier one of the things we need to take into account here is the community the framework/language has and what support you can get from online sources. In my opinion both PHP and NodeJS have a very good community and I believe NodeJS will eventually surpass that of PHP if it hasn’t already.
The reason for this is that it’s such an evolving project that’s gaining a lot of popularity (mainly due to it’s ease of use since its Javascript based) and that just attracts more people into it. Furthermore it’s supported basically at this point by most services and backend systems which gives it an edge. I think those two combined and considering how much growth it has seen NodeJS can replace PHP. If you are looking for this kind of thing in your project definitely take it into account.
Can NodeJS Replace PHP As A Cloud Solution
In a world where everything has to scale we are basically talking cloud. PHP has been traditionally a heavy engine based solution that requires a heavy stack to run. Originally it was based on Apache along with some modules and the php command line runtime libraries. This made it very difficult to make it more modular and lightweight so it can exist in the cloud. Over the years the engine improved but it never kind of got to the point where it’s easy to bundle.
Having said that NodeJS on the other hand is very lightweight and it can be bundled fairly easily on a cloud solution such as AWS Lambdas. If we look at the AWS Lambda server less setup we will notice that the default engine is NodeJS! This says a lot about the popularity but also for the potential of NodeJS on replacing PHP.
To make matters worst if we try to look for a PHP engine for AWS Lambdas in the list we will not find anything! This can be shown in the image below.
Having said that there are ways to do it with a custom runtime but that requires the user goes out of their way to maintain and setup their own image that spins up PHP which really takes away the beauty of having a good server less system that’s maintained by AWS. In my opinion NodeJS can definitely replace PHP in the cloud.
Can NodeJS Replace PHP As A Language
I kind of left this one at the bottom of the list because I think the actual question here is if PHP is better than Javascript. As you already know this has been discussed extensively and compared by a lot of people and I think it comes down to preference. Both languages are pretty good in my opinion almost equal but Javascript gives different coding styles like object oriented, functional etc which may be preferable to some people.
I personally like both of them and on this one I will not be able to tell you if NodeJS can replace PHP as a language I’ll give it a neutral equality.
Can NodeJS Replace PHP In A Corporate Environment
This is a very common thing I tend to get these days if language X can replace language Y in a corporate environment. What you really need to be asking here is are both professionally supported by teams that will act upon issues such as security vulnerabilities or core bugs in a fast and proper manner.
My answer is that both NodeJS and PHP have a great development and support team. I remember when PHP was originally released there were a lot of security bugs that were found. The reason for this is that it was mainly the beginning of making web framework development accessible to the masses, prior to PHP it was really C and CGI which was not very popular. So the learning curve PHP went through wasn’t only as a language but also overcoming new obstacles that no one had faced before.
So to be fair with it I think it’s a mature language and libraries that have existed pretty well and I do not think NodeJS which has taken into account all the learnings of PHP is any better at this stage. I’m going to go off in a leap here and say both can be well suited for a corporate environment, of course if you are looking to scale in the cloud always prefer NodeJS in my opinion. If you have your own clusters of servers and like to maintain that then the choice is equal in both PHP and NodeJS.
Is NodeJS As Stable As PHP To Replace It
That’s also another question I get a lot lately. I think NodeJS the v8 engine has been pretty stable the past few years. When it originally started it had a bunch of issues and it did not work properly even failing at basic tasks. However the growth it has seen and the results from it have been exceptional and these days I believe it’s one of the most stable projects out there.
On the other hand PHP has been stable for quite a few years now without any major issues I can think off with the exception of a few performance hits that it had that were quickly addressed. Having said that I think NodeJS will continue to improve and potentially become even more stable with the improvement of express. These days I think it’s a tie between the two and you can trust both and sure NodeJS may replace PHP in the future when it comes to stability.
Can NodeJS Outperform PHP And Replace It
The never ending question on performance. Is NodeJS really a good replacement for PHP when it comes to execution speed? Well there’s a lot to be said here and I think the benchmarks out there prove one and only one point. NodeJS is indeed faster than PHP and it can definitely replace it. In the image above by a great article on hackernoon shows this very well.
I personally feel it outperforms it in pretty much every way when you are running your business logic. There’s a few exceptions where you are interacting with database drivers particularly reading where NodeJS may lose but all in all I think NodeJS can replace Java for speed of execution. Keep in mind that both frameworks mainly are used as monolithic executions ie they are invoked from a web interface and generally only I/O is an issue.
The above graph from kinsta.com portrays very well the fact that NodeJS v8 engine is basically single threaded once invoked. Contrary basically to PHP which supports multi-threading natively.
There are cases however that you may want to run a local application or even execute a lot of tasks in parallel. This is I think where NodeJS has a big weakness and actually loses to PHP due to the lack of concurrency. Before you question this let me tell you again, NodeJS has pseudo-threading meaning it executes everything in a single thread. On the other hand PHP supports native system threads and can do multi-tasking a lot better so when it comes to the concurrency part of things NodeJS cannot replace PHP as it will always lose the execution speed battle of parallel tasks.
Can NodeJS Replace All The Features Of PHP
The last thing I want to touch upon is if NodeJS can replace all the features of PHP. As you know both languages have a very similar set of base libraries that they come with so when we are comparing the essentials both are pretty good at getting the job done. If we start diving a bit further though and try to niche out on specific things I think PHP has more to offer than NodeJS in the existing state.
We went over the popular Laravel framework but it does not stop there. PHP can be setup in various environments and also offer a lot of extensions that are related to security, fraud detection, availability and general performance. NodeJS does have a lot of third-party libraries and services that try to get to that level but I do not think it’s there yet. For example something I had faced in the past is user management solutions.
While both of them have offerings I think PHP does that a lot better out of the box. When you are with NodeJS at least in cloud you need to do a lot of things from scratch or rely on a solution like AWS cognito. What I am trying to say I think PHP has all those minor things that are generally unavailable in NodeJS. Before you rush to tackle me I’m sure there’s resources to do everything but they are not readily available nor stable enough for my needs. So this one may be a bit of subjective view on the matter and I will be the first to admit that it may radically change in the future.
For now however I’m going to stick and say that NodeJS cannot replace PHP when it comes to features.