Node.js vs Laravel

Post by on January 25, 2014

There are a plethora of web frameworks to choose from and even more options when you combine them. I want to take a look at comparing two frameworks, Node.js and Laravel, that, in my opinion, are the most advanced web frameworks. And, I want to make one single point: do not compare Laravel and Node.js as though one is better than the other, rather, compare them against which is the best tool set for the job or problem you are trying to solve.

Disclaimers

First, a few disclaimers. One, when I refer to Node.js I am referring to the entire Node.js ecosystem. I know calling Node.js a framework is a misnomer, but no single framework in Node.js is a match for most of those in PHP. But, that's part of the brilliance of Node.js! You don't need a big honkin' framework because everything is so modular; pick-and-pull what you need for your application. Thus, I think in this sense it works to compare Node.js and Laravel. Two, I define a web framework as the basic underlying structure on which you build an application. A web framework, then, is typically composed of a routing and request handling system, helpers, a database abstraction layer, some form of templating and rendering views, and session handling. Three, I may bring up arguments between Node.js and Laravel that are really JavaScript vs PHP arguments. You can't throw out the baby with the bathwater, I say. Again, we are looking at two different tools and what they have to offer. Four, this post is not comprehensive. This post is a jumble of ideas that I'm attempting to put in coherent form, thus not a well-polished piece of writing.

Similarities Between Node.js and Laravel

Second, I want to explore the ways in which Node.js and Laravel are similar:

  • package manager
  • routing
  • RESTful routing
  • templating
    • you can choose from a large number of templating engines for Node.js, many of which have client-side implementations as well
    • Laravel uses Blade templates, but there is also support for Twig
  • non-blocking / event based
    • this is inherent in Node.js
    • Reactphp for Laravel
  • web sockets
  • ORM
  • database drivers: MongoDB, MySQL, etc
    • they are both very comparable; just search for a driver for the database of your choice
  • namespacing
  • dependency injection
  • data typing
    • they both use dynamic weak-typed languages (some disagree), meaning variables can change type at runtime and the language will infer a variables type, i.e. adding the string "2" and the integer 2 will result in an integer 4.
  • interfaces
  • helpers
    • basically anything in npm can be installed as a helper in Node.js (for example, see Underscore.js)
    • basically anything in composer can be installed as a helper in Laravel, but a number of helpers are already provided

Strengths Weaknesses Opportunities and Threats (SWOT)

Third, I want to give a quick Strengths Weaknesses Opportunities and Threats (SWOT) analysis of each.

Node.js

  • Strengths
    • vibrant and engaging community
    • changing fast, so you can be an influence
    • modular from its beginning
    • non-blocking / very fast
    • ability to share code between client and server (since it's JavaScript)
    • JavaScript a very common language, especially on the web
    • the community tends to be biased in support of non-relational databases such as MongoDB
  • Weaknesses
    • not good with computation heavy apps (reference)
    • not as mature as "alternatives" (though, to be fair, there are no alternatives)
    • event-based programming can be difficult to work with: debugging, promises, etc; it takes a lot of training / experience to do it well
  • Opportunities
    • maturity: simply needs time, since they have the community involvement
    • develop comprehensive frameworks (like a "Laravel" for Node.js) so you don't have to build your own framework from scratch (see this large list of prospects)
  • Threats
    • I see no threats provided the status quo continues; in other words, they are on the right track. A very low probability threat would be something like a resurgence / revolution in Ruby or Python development, or if PHP's current revolution wins over the Node.js crowd.

Laravel

  • Strengths
    • It has everything I loved about CodeIgniter combined with everything I wished it had from PHP 5.3 / best software practices
    • structure: with MVC and PSR-0 you have terminology to talk about where things should go and every line of code has an expected place
    • there is a large community in PHP that advocates unit tests, and PHP supports interfaces; two things that help ensure consistency in your application
    • it provides patterns to help you use current best practices in programming: dependency injection, facades, unit tests, interfaces, PSR-0 (there are a few great Laravel books on these)
    • PHP has a large and well established community
    • the community tends to be biased in support of relational databases, such as MySQL
  • Weaknesses
    • not inherently non-blocking
    • PHP has enormous baggage from PHP4 and earlier: just look up anything about "PHP is the worst language ever"
    • there isn't a large community around Laravel, specifically, and the community isn't pushing for support / acceptance
  • Opportunities
    • PHP has a very active community and with PSR-0 it will be easy for Laravel to adapt and adopt from the large pool of PHP code, i.e. out-of-box support of non-blocking, multi-threading, etc
    • Laravel is a beautiful framework which should make it easy to push adoption, especially among the CodeIgniter and CakePHP crowds, and even more so among PHP crowds looking at Node.js or Ruby on Rails
  • Threats
    • Pretty much everything is a threat to Laravel because it is written in PHP. Other frameworks in other languages, such as Ruby on Rails, have had support for the things Laravel is doing (and planning to do) for much longer and are, therefore, much more mature. However, PHP isn't going anywhere anytime soon and other PHP frameworks are still catching up on implementing the current best practices.

Conclusion

Node.js and Laravel are brilliant frameworks. They both hold enormous promise for the future and have some of the best features available of any framework. But, they have their biases. If you have an application with low computation and high availability requirements and are going to use a BASE or non-relational database, Node.js is favorable. If you have an application that is very complex and you need the highest level of consistency and organization, and if you are working with ACID / relational data, then Laravel is favorable. As a final thought, consider Linus Torvald's thought process surrounding his decision to develop Git for Linux as seen in his "Tech Talk: Git" presentation at Google.

Further Reading

Older Posts ยป