David.dev

PHP vs Nodejs vs Go


Web programming languages comparisons have always been an amusing exercise. Whenever you google something like PHP vs. Node.js you almost certainly end up the usual answers that says"node.js is not a language..javascript is..."or"there is no better programming language but just the best tool for the job" this is of course only part of the story and doesn't really address the question.

I have even seen several replies asking people to learn both and then decide - doesn't this defeat the purpose of the question to begin with ?

Indeed there is some wisdom in gaining proficiency in several languages but sometimes you just want to know which is better for web development -- or at least what is better according to other people that had experiences with both.

Whilst I am not a professional programmer I had some experience with PHP, Node.js (yes I know, server-side javascript) and Go also known as Golang. 

So here it is, my non-professional opinionated review of the differences:

PHP

My experience from PHP is somehow dated. I started using when PHP was the web programming language to be used. 

Most of web-code before PHP was the infamous /cgi-bin (internal server error anyone?) perl. In my experience PHP has the best learning curve vs Node or Go and you can pick up things very quickly. Everything you need for the web is available as a standard function: database connections, post/get variables, json handling and much more. You don't need a template engine because PHP *is* a template engine. So there is nothing really wrong with PHP. I hear that PHP7 had also some great speed improvements. In terms of speed I did benchmark it with Node and Go and there is really no major speed difference for a small or mid-size app (yes what most of the people will be writing anyway).  There is nothing to dislike about PHP but code quality will vary greatly. You have complete freedom on how to do things and freedom can become confusion. I am not a huge fan of PHP frameworks so I can't really talk much about them.

To me in year 2019 PHP is still a very solid way to code. Personally I think it misses a bit of the sparkle of the new "cool" languages like Node (yes, I still mean server side javascript) or Golang. 

Node.js

Extremely popular for various reasons. There are lot of packages you can use to develop your app and if you know javascript (who doesn't in web development?) you can pick up a node framework like express very quickly.  Note that this ain't PHP so you do need a framework to be up a running.

I tried to write a small app without using a framework and you basically will end up rewriting everything: routing, body-parsing (to set a simple post parameter), static files rendering etc. Interesting exercise to understand Node but highly impracticable. Node is not a programming language but essentially a language engine to run server side javascript code. 

Code can get very messy too so is not a safe heaven but deployment is a pure joy with tools like pm2. For me it was not the easier learning curve but again I had very limited (and probably still have) experience with javascript.  If you are looking for something very contemporary, potentially highly scalable and with a high cool factor you will be right at home with node.js.


Golang

Here is gets a bit tricky. Golang has pretty much everything you need for the web. There is an excellent tutorial for web apps. You don't really need a framework as most tools are included in the standard library (Webserver, templates, parsing, routes really pretty much all you need). It is a Google project so -- as you can imagine -- it was written by very clever people for clever people. Is a compiled language and the syntax is more similar to C than PHP or Javascript. Can you do a simple website like easily ? of course you can. Deployment is a simple as typing "go run". Code can be formatted automatically with "go fmt". A lot of things to like about. I am not a huge fan of the syntax and the error checking system. Often I did hit some roadblocks and the community is much smaller (and I really mean much) compared to PHP or Node. As a result of that the number of packages are also limited but I can't really say that you would miss the tools you need for a small web app. The speed is really impressive so if you are looking for having the speed of a rocket you should give it a try. 

The Best? 

In summary "use the best tool for the job!" (just kidding) I would say that for small web apps the best choices are probably PHP or Node.js with a good framework like express. I would also think that Go is an excellent choice if you like (and can pick up) the syntax. In fairness I have seen go tutorials and courses mostly discussing about using go for APIs. I think this is what Google invented for but I did use it for pure web apps with very encouraging results. 

My experience has been good with all 3 and I continuously change my mind about which one is "best" for -- my personal focus -- small web apps.  At the moment I am enjoying the learning curve of javascript/node.js and discovering new interesting packages but I am also intrigued to try more things in Golang. 

The big bonus of node.js is the fact that if you learn it you can also create cross-platform (Mac OS X, Windows, Linux) desktop apps (with ElectronJS ) or mobile apps (iOS and Android) (with Framework 7 and other frameworks) so may be javascript -- given the cross development opportunities -- is the future?


11

made with ❤ī¸ by david.dev 2024 RSS Feed