MERN Stack vs Laravel - From a Developer's perspective
I’ve personally used both Laravel and MERN stack, and still have ongoing projects with both.
There are many things to consider before choosing a stack to work with.
For me, it boils down to the following 2 things.
- Do I need SEO for this project? If yes then Laravel is more favorable over MERN stack.
- Do I need WebSockets for some “live” functionality? then Node’s the obvious winner.
Now don’t get me wrong, Laravel can do live stuff (called broadcasting) and MERN stack can be optimized for search engines, but is it recommended? The answer is no, not yet.
For example. Take my site, it’s a SPA built with MERN stack, is faster, securer, but not ideal for SEO.
I don’t want to make this yet another article on PHP vs NodeJS, there are already pretty good ones out there.
MERN Stack vs Laravel
Ok, so here is a roadmap of comparisons we’re going to go through. I’ll try to be as much straightforward as possible.
- Popularity & Trends.
- Performance, the thing most clients care about.
- Security.
- Ease of Development.
- MVC architecture.
- Deployment options and costs.
- Search Engine Optimization.
Popularity & Trends
Here a few graphs I got from a quick search at Google Trends. All these graphs show data from over 5 years ago to 2020.
1. Laravel vs NodeJS - Google Trends
2. PHP vs JavaScript - Google Trends
3. MySQL vs MongoDB - Google Trends
4. Laravel vs React - Google Trends
Looking at all these “Search” trends shows that Laravel is, in fact, more popular than MERN stack.
According to SimilarTech, NodeJS is powering more websites than Laravel.
Verdict: Laravel won worldwide, Node is catching up fast. In the US, NodeJS is more popular.
Performance - Which one performs better?
I’ve seen numerous clients who just want to switch to Node because it’s faster. While that is true, they don’t know that it isn’t always the case. Comparing Asynchronous to Synchronous isn’t a good way to benchmark.
It is important to note here that since in MERN stack, React is used for client-side, it is significantly faster than Laravel’s server-side rendering.
- PHP performs multiple tasks at a time depending on system resources. You will notice wait time when all resources are at max usage.
- NodeJS performs multiple tasks in a queue, in an Event Loop, which executes tasks in a loop. These tasks can run simultaneously as long they are asynchronous, otherwise, it can make you experience wait times.
Also, MongoDB is faster than MySQL, not but huge margins, but it is. It’s also more scalable. Here is a benchmark from Simform, on MySQL vs MongoDB for the same commands.
Verdict: Node is faster for same resources utilized, Laravel is not slow either if done properly.
Security - Which one is more secure?
Security mostly depends on the developer, I mean there is only so much we can expect from a framework. Here are a few facts.
- Laravel does provide CSRF tokens, hashing, and other security layers by default.
- MERN stack relies on a lot of packages If there is a vulnerability NPM tells you in CLI.
- You have to take care of Hashing and Authentication yourself in NodeJS, but there are many helpful packages, like Bcrypt, JWT, Passport, etc.
SSL provides a required layer of encryption, I have an article on How to Install SSL on Express Server.
Verdict: Both are secure, Laravel provides a lot by default, but many packages are available for MERN.
Ease of Development & Extendibility
You must have heard a popular saying, ”With Node, you can hire JavaScript developers for frontend and backend”. JavaScript is an easy language, but Laravel provides many tools by default.
- Laravel is packed with loads of awesomeness,
- Eloquent ORM.
- Database migrations and seeding.
- Unit testing.
- Caching tools.
- Events.
- Blade templates.
- Artisan CLI.
- Logging and error handling.
- Authentication and session management.
- Useful official packages such as Cashier, Socialite, Telescope, Passport, and more.
- MERN stack provides vast extendibility.
- Backend packages.
- Express as the main Framework.
- Mongoose for Accessing MongoDB.
- JSON Web Tokens, for stateless authentication.
- Bcrypt for Hashing, compression for GZIP, and access to all NPM packages.
- Frontend packages.
- create-react-app is a good package to start with.
- Bootstrap, for base CSS framework.
- Axios for consuming backend API.
- React Router is a good package for frontend routing.
- There are many other packages available for React.
- Backend packages.
For me, it takes longer to develop the Laravel app, even though with MERN I have to developer Frontend and Backend separately.
Model-View-Controller (MVC) architecture
Laravel was the first time I encountered the MVC paradigm. It provides awesome ways to do it even more elegantly. Laravel can also provide API routes and stateless authentication.
In MERN stack, Views are handled by React, which makes requests to the backend. Many developers put logic, and database queries directly into API routes.
Deployment Options & Costs
Laravel is deployable to any shared hosting that supports PHP (99.99% do). You just have to copy files, and 1-2 steps after that.
For Node, Some shared hosting providers support it, but mostly it is deployed to VPS via SSH.
A few years ago, I made a Node App (Not MERN), I thought Namecheap (shared) would let me host it. I soon found out that they don’t allow MongoDB on shared hostings, I had to recode my entire App to be compatible with MySQL.
Verdict: It’s cheaper to host Laravel Apps.
Search Engine Optimization (SEO)
Google’s and Bing’s crawlers have become more and more advanced over the years. They do crawl SPA’s relatively well now than a few years ago.
It’s a good idea to have landing pages and blog in Laravel and actual App (product) to be a SPA.
Verdict: Laravel is recommended for better SEO, but React is faster.
Final Words
Laravel is better for many clients. These days it can perform almost thing Node can perform. Laravel can also use MongoDB too.
Node is just too popular, Laravel utilizes it too. MERN stack is the one I love, although Laravel is awesome.
Choose MERN Stack if,
- You want to build an API, which may be consumed by phone apps in the future.
- You love ReactJS, as I do. It creates beautiful things.
- Requirements contain WebSockets for live chats.
- SEO is not a big concern for you.
- You want awesome levels of render performance.
- You just can’t leave NPM packages.
- JavaScript holds a special place in your heart.
Choose Laravel If,
- You love Laravel, its features, and packages as listed above.
- SEO is a major priority.
- You want to host it on cheap shared hosting.
- Server-side rendering is something you need.
- You love the Composer package manager.
- PHP is something you love.
Last updated: 7th May 2020