HACKER Q&A
📣 kypro

Why are so many PHP projects moving to Node?


I started my software engineering career as a PHP developer about 15 years ago. Looking back now I understand why PHP had a bad reputation - the language objectively had a lot of problems and the PHP ecosystem in the mid 00s was very immature compared to the battle tested ecosystems of Java and .NET.

But since then, and with the release of PHP 7, the language and ecosystem has matured massively. For one, Laravel is excellent - the framework is well designed, the docs are some of the best I've ever worked with, and the developer tooling is (in my opinion) unrivalled.

I work mostly on Node / Java back ends professionally these days, but I find myself almost exclusively using Laravel for my personal projects. THe reason being I'm so much more productive in PHP & Laravel compared to Java. And don't get me wrong, Java is great for building enterprise software, but for small to medium sized web projects it's overkill.

I also have PHP projects which I built well over a decade ago that run perfectly fine today. Meanwhile in Node land it's not uncommon for projects just a few years old to stop working altogether because some package I was using is no longer maintained and hasn't been updated to support the latest version of node. And even when the project still runs the ecosystem tends to change so much that you have to do significant refactors every few months just to keep everything reasonably up-to-date. I think any JS developer can relate to the fact that a good chunk of your time working on JS projects is spent refactoring code because Gulp is no longer being maintained, or LibSass has been deprecated in favour of Dart, or because the community just decided that you need to use React hooks now...

But another reason I don't use Node is simply because JS sucks, even when compared to PHP < 7. It's a poorly designed language that requires multiple layers of tooling just to make it acceptable for use in larger projects. And again, when the ecosystem is changing so often any tooling you're using needs to be updated constantly.

But this isn't a rant about JS. I'm just wondering why in 2023 I seem to love PHP more than ever and the developer community broadly seems to be migrating more towards Node? Can someone explain why I'm wrong about this because when ever I tell any of my Java / Node colleagues that I love PHP they tend to roll their eyes.


  👤 41amxn41 Accepted Answer ✓
I wouldn't pay too much attention to what "the webdev industry is doing". That's how we ended up with MBs worth of javascript to display a simple website, not to mention the cpu required to render single page apps that won't even let you open a separate tab and constantly break.

Most people in this industry are either junior devs that have no idea what they're doing, mid level devs that fall for the hype and don't like "boring" tech (battle tested, reliable) and end up using stuff that's not even production ready, and senior devs that overengineer and optimize prematurely.

Just keep on your path and don't pay attention to the dummies. PHP is great and will never die.


👤 root_axis
Three major reasons.

React, Typescript, and isomorphic/universal JS.

The reasons for React's dominance is a separate topic, but if you're working with react, node becomes a natural fit for the backed because you can render the same components on the server or the client.

Again, the reason for TypeScript's success is a separate topic, but node is the go-to backed if you intend to build with typescript. All things being equal in the interpreted scripting language world, typescript's type system sets it far ahead of php/python/ruby.

Being able to build with one language for both front-end and back-end is a nice perk, but being able to reuse business logic in both environments is massive. e.g. sharing object structure types and interfaces between environments ensures API ingress and egress remain consistent, the same code used to validate form inputs on the front-end can also be leveraged to produce API validations on the backend and many other use-cases.

One runner-up reason: npm. Yes, npm has had a reputational hit due to some excesses of the ecosystem in years passed, but at the time when node was picking up steam, the php composer experience was terrible, whereas npm set the standard for stupid easy package management... yes, it came at the cost of a 2gb node_modules dir but this is (mostly) a developer vanity problem rather than an actual problem (unlike resolving composer dependency quagmires)

> But another reason I don't use Node is simply because JS sucks, even when compared to PHP < 7. It's a poorly designed language that requires multiple layers of tooling just to make it acceptable for use in larger projects

Any specifics? The reality is that PHP and JS are both wart-filled messes, I certainly don't see any substantive justification for the idea that node is worse than PHP.


👤 ARandomerDude
I think it’s the culture. The code quality of almost every PHP project I’ve seen is atrocious. I’m not saying every JS project is perfect (far from it), but amazingly well-written JS projects are ubiquitous.

So when I ask myself “how much do I trust complete strangers on the internet?” the answer is “not much, but even less than that if it’s written in PHP.”


👤 treve
I've been a PHP programmer for most of my professional career and switched a few years ago. PHP has a bad name for a long time. True or not, this started weighing on me and I shared a lot of the opinions you wrote here.

People will continue to roll their eyes. Whether deserved is besides the point. I was no longer interested in being a 'PHP programmer' and have to justify my worth. PHP is by all measures on it's way out. If you are looking at other ecosystems of course you're going to find things that aren't great. PHP has those too but in the 15 years you've been doing it you've created habits that perfectly avoid those. You're not going to attain those same skills immediately elsewhere, and the things that are worse from your perspective are going to stand out more than the things that are better.

You've tied your professional identity to a programming language that people dislike. It's not a fun place to be, but trust me you'll be better off in the long run. This has NOTHING to do with language features, and everything with your feelings and bitterness. Your post is full of emotions. It's not worth feeling this way, it's just a programming language.


👤 willio58
Once I accepted that JS might not be the worst language in existence I slowly got to the point where now JS is my go-to language for most things. Specifically with TypeScript, I feel like I have the best of both worlds. I have a typed scripting language that works for the frontend and backend, and things just flow so nicely.

👤 whalesalad
re: js - "It's a poorly designed language that requires multiple layers of tooling just to make it acceptable for use in larger projects." - ok, isn't this the pot calling the kettle black?

On a more serious note, i've been thinking recently that the more experienced you become with programming, the more you will thirst for functional programming or something close to it. I think that we see this with the maturation of the modern JS ecosystem too - with a trend towards thinking functionally, rendering functional components, limiting side effects, top-down data flow etc. PHP is not the easiest place to do functional programming. PHP is also not a glamorous place to be. Laravel is cool, but you are still gonna want something like React or Vue if you are building a modern front-end so why not go all-in on JS? I am not arguing for this - but I can see the argument being made by the community at large so I am not surprised to see PHP devs moving into JS.

You are in like the 1% - the mythical PHP hacker who loves the language. You will live a lonely life in your mystical PHP dragon cave high upon the on the hillside of Mount Lerdorf. This is the life you must be prepared for.


👤 sam_goody
I am not sure they are.

There was a point where colleges were only teaching Node, as JS was very fashionable. I've reeived applications where the answer to languages known are: Javascript, TypeScript, React, C++.

But, anecdotally, we moved one server to Node during the hype cycle, and that taught us enough to not repeat the mistake.

Others in the industry I have contact with (admittedly somewhat of a self-reinforcing circle) feel the same way.

Unfortunately, it is harder to find a good PHP dev.

EDIT: Actually, in my experience, the pool of PHP devs is smaller, but the average quality is higher.


👤 auggierose
I moved from Swift to TypeScript last year. Best decision ever, TypeScript is super productive if you treat it just as a fancy linter, and it gives me access to a vast ecosystem that runs everywhere. Obviously then, Node is the choice for the backend.

To be honest, I find it hard to justify using anything BUT TypeScript these days.


👤 dogleash
> Can someone explain why I'm wrong about this because when ever I tell any of my Java / Node colleagues that I love PHP they tend to roll their eyes.

You're not wrong so much as out of fashion.

It's very important to recognize how much industry trends are driven by fashion. But being fashionable also makes an ecosystem good. Well, at least makes it better. For certain definitions of better. Lots of development attention that means there's probably a highly visible project building exactly the bells and whistles that will garner praise and more attention for the ecosystem.

You can make your slow, measured, careful decisions about tech to use. But webdev is full of YOLO projects too. Churn and fashion are always going to be at your door.


👤 bluelightning2k
I used to use PHP in the long-long ago.

Full stack typescript for me is SO much nicer. Occasionally there's code-reuse but more often it's interface reuse for type-safety and autocompletions. This yields a lot of correctness/safety in a large project.

No context or tooling switching.


👤 noahtallen
> It's a poorly designed language that requires multiple layers of tooling just to make it acceptable for use in larger projects.

The thing is, most of this tooling isn’t even related to the language itself. In NodeJS, you need basically none of your the tooling. Here are reasons why tooling is used:

- Webpack. Files need to be minified because code is downloaded nearly every time you access a website. (Not a language problem.) This also leads to a whole other class of optimizations like dead code elimination.

- Babel. Can’t guarantee client-side runtime layer, so need to make sure new syntax is transpiled. Not a language problem.

- Eslint. Ideally you’d use a linter in any server-side project, like PHPCS for PHP.

- Typescript. This is a language problem. :p At least PHP has some types now!

On Node, you don’t need webpack or babel or any similar set of tools, because Node can resolve imports and you know which Node version you support. Other tooling, like dependency management and linting, would be normal in other languages too.

On the client, you need a huge set of tools just to deal with the fact that your software is literally downloaded over the internet as part of the startup process. That comes with a huge set of performance optimizations related to bundle size that other languages simply don’t need to care about. That’s why there’s so much extra tooling in the JS ecosystem.


👤 Eric_WVGG
Javascript indeed sucks, but Typescript whips

To call Javascript "poorly designed" when having a discussion about PHP is… a bit jarring… Both PHP 7/8 and Typescript are huge improvements over their forbearers, but it seems indisputable to me that fundamental Javascript is at least a better-designed language than fundamental PHP (circa v3), and contemporary Typescript is better-designed than modern PHP.

(creds: I've been writing PHP and Javascript since around 1997)


👤 TiredGuy
Well, part of it is that PHP was initially one of only a few options, and since then new languages and technologies like Node have appeared and slowly eroded that market share by the simple fact that they are competition. Node became popular for the many good qualities it has: isomorphism, simplicity, etc., and I don't think php devs in particular moved to node as much as devs in general gravitated toward it.

If you look at PHP vs Node in Google Trends, you can see the PHP decline was well on its way before Node.js came on the scene in 2009.

I used to love PHP, but these days JS is good enough that I don't feel the need to look back. My personal JS projects still look PHP-ish in the sense that they're very simplistic, often lacking a build step and often even lacking a framework. I do like having more control over the server logic than what I remember having with PHP (granted this was the days of WAMP and LAMP, and I hear with docker and nginx things are nicer now). I also like the fact that I can go to a single place (npmjs) for both my browser-side and server-side libs because sometimes I haven't decided yet where it'll reside.


👤 dzikimarian
> developer community broadly seems to be migrating more towards Node?

How did you came to this conclusion? I work with PHP teams daily and they don't think about moving, but even if they did I wouldn't expect them to seriously consider node. Overall I would say that in the last few years there was increase in number of competent PHP developers.


👤 yamtaddle
> But another reason I don't use Node is simply because JS sucks, even when compared to PHP < 7. It's a poorly designed language that requires multiple layers of tooling just to make it acceptable for use in larger projects. And again, when the ecosystem is changing so often any tooling you're using needs to be updated constantly.

TypeScript, ignoring about half the language features many of which are "oh my god please never actually use this" (e.g. all the distinctive features of prototypal OO), and finally being able to concisely tell the language to please let you treat async calls the way everyone's always wanted to be able to treat them 90% of the time for the entire existence of JavaScript and Node (async/await) has made the language downright tolerable.

The culture and ecosystem still blows, though, you're not wrong there.


👤 brnewd
I think your issue is having to use a language/runtime you're not productive/happy in. I switched from PHP to Node.js of my own choosing and loved TypeScript everywhere and a Java like runtime vs a state less execution model. I found the npm ecosysteem much richer and accessible than Packagist / Composer. However if I was forced to write in Python, I would have similar complaints.

👤 tonymet
Based on the trends in "scripting" language programming over the past 30 years including Perl , Python, PHP & Node, i've noticed it's not the "best" language that wins . There needs to be an intersection of ease of use, a broad component library , adequate toolchain, quick iteration and a vibrant community.

Perl & PHP were two examples of languages that were particularly bad fits for their use cases – poor performance, buggy syntax that led to lots of runtime bugs – both were very successful for a time.

To answer your question: Node meets the above qualities reasonably well. It also is ambiguous enough to allow lots of navel-gazing over academic tangential topics so people can avoid actually getting work done and waste a lot of wall & CPU time doing so.


👤 yusufnb
We recently moved all our projects to Node. Few thoughts -

1. The TypeScript tooling with Node has improved tremendously. Frameworks like Nest make it simple to work with it.

2. There are some really good frameworks that, over the years, have remained simple and just work. Example - Express, Sequelize, etc.

3. Same developer can make changes on both the frontend and backend since the language on both sides is TypeScript now. That simplifies building features as less coordination is required for full feature development.

4. Deploying Node apps is overall simpler. Be it VMs, containers, or serverless. Horizontal scaling is cheap, and most applications don't need much processing optimizations there.


👤 valand
For me, the reasons are:

- PHP's capability is limited in a sense that its main use case is akin to a template engine rather than a full fletched executable. This puts a lot of limit in PHP

- TS steps up JS' game. Like what other have said, TS brings the hassle of maintaining complex codebase down quite a lot.

- NodeJS is a stepping stone for many frontend developers to learn backend because of the same language used.

- JS' syntax and capabilities, while having inherent unavoidable footguns, allow expressive code (I might be partial on this, the last time I used php is a long time ago)

Edit: formatting


👤 gremlinsinc
I want so much to get off laravel, because it feels bloated, but I can't for the life of me find a decently structured way to do so in node, rust, golang, etc. The best I can do is maybe sprinkle in vue/react + inertia on frontend, and filamentphp on the backend, honestly I was close to switching until filament came out, I hated doing admin dashboards, and now I don't have to do as much.

👤 maerF0x0
Years back at ZendCon (maybe 2011 or 2012?) one of the keynotes mentioned they liked ZendFramework over something from Java* because they can hire developers cheaper than for other languages. That was my sign to move to another language.

* The memory is fuzzy what the comparator was, the point stands


👤 clementmas
When using React, Vue, Svelte, etc. for large SPAs, so much of the logic has to be duplicated from the backend to the frontend. That's why it's tempting to ditch PHP and use a JS meta framework to be able to reuse code (types, utils, etc.).