DEV Community

Tyler Smith
Tyler Smith

Posted on

Reflecting on a year with Node.js and why I should have stuck with Laravel

Earlier this year, I was two months into building a full-stack JavaScript app. I used an Express server, set up Next.js for server-side rendering, added Chokidar for instant server reloading, used Next.js's Webpack config to compile my server's TypeScript code, hooked up cookie authentication with Argon2 encryption, found the perfect Node ORM, and had the app running in separate containers for Node, PostgreSQL and Redis.

After two months of hard work, all I had built was a mediocre server-rendered CRUD app hacked together with two-dozen NPM libraries. If I had used Laravel and jQuery, I could have built this all in a weekend.

After a year of building Node.js apps, I discovered I was spending more time piecing together tools than writing application code. Laravel gives me 80% of my tooling out-of-the-box for 20% of the work. If moving fast is important to you, you should consider batteries-included frameworks like Laravel and Rails first.

The failed promises of full-stack JS

Full-stack JavaScript evangelists preach that developers can work faster by staying in one language and sharing code between the front-end and back-end of an app. I spent a year chasing that dream without ever reaping its promised benefits.

While Node.js and ES6 are both JavaScript, they are very different implementations. Node historically hasn't worked well with ES6 modules, which means you must compile ES6 code to CommonJS to run it on the server. Configuring Webpack and other bundlers is a completely separate skillset from application development, and it can take days to set everything up correctly. Opinionated tools like Next.js have eased this pain slightly, but its serverless-first approach can make it feel constraining when implementing features that would be standard in a server environment (like using the filesystem).

I had hoped that by staying in a single language I could at least gain speed by not switching contexts, but instead I spent my time switching between endless tabs of third-party package documentation in my browser. Node.js doesn't have a killer back-end app like Laravel that the community has rallied around. Instead, it has a multitude of frameworks gunning for the spot but with no significant adoption or traction. To mitigate the risk of picking a framework that could disappear, many developers use Express.js and piece together an application around that. Unfortunately, using this approach leaves you with countless decisions to make. What ORM or DB driver do you use? Cookie auth or JWT? What encryption algorithm is best? What library should you use for data validation?

Every one of these decisions can take a week to fully understand the implications of, all while you could have been building your app. It's death by 1,000 paper cuts.

Laravel: Rapid Application Development done right

Laravel is an incredibly productive application platform. It comes with all of the things you'd expect from a batteries-included framework: routing, an ORM, middleware, authentication, validation, migrations, and testing (just to name a few). But Laravel has two killer features that other full-stack frameworks don't have: a vibrant first-party package ecosystem and incredible documentation.

Laravel has a first-party Stripe integration for billing. The framework includes a first-party integration for users to use social OAuth to log in. Laravel has first-party app scaffolding, a pre-configured docker environment, a powerful queue system, and if you're willing to pay a few extra dollars, you can get managed Laravel deployment and a gorgeous application dashboard.

Laravel's first-party paid modules are a differentiator: its paid offerings have made it a self-sustaining business with full-time employees who can maintain first-party packages and sweat the details on things like documentation.

Laravel's documentation might be its most powerful feature. While many documentation sites feel bleak and inhospitable, the design on Laravel's docs is bright and inviting. The docs are well-organized and maintain a consistent voice throughout the pages. The docs also have an instantaneous full-text typo-tolerant search, which will not only take you to the correct page, but also put you on the relevant part of the page.

Laravel's powerful first-party integrations and superior documentation let you get to the business of building your application right away. Rather than comparing the six most popular ORMs for Node, you use the one that comes with Laravel. Rather than researching all the ways to authenticate your users with their social profiles, you use Laravel's first-party package. All of your framework's documentation lives in one place instead of across a dozen sites, and you can leverage the entire Laravel community when you have challenges instead of the few people using the same libraries as you.

What I've learned

What I've learned is if you want to develop applications quickly, it isn't about staying in one language: it's about reaching for the tools that let you move quickly, whatever those are.

I use Laravel because it lets me build my server-side apps fast. I use React for most of my front-end web applications, and Laravel gives me the tools I need to spin up the backend quickly. On sites where SEO is important, I can pair a server-rendered Laravel site with Vue widgets for the more interactive parts of the site. Laravel Mix's zero-configuration bundling makes compiling a project's assets a breeze.

Rather than sharing code between the front-end and back-end, I've learned to move almost all of my business and validation logic to the back-end, and I consume it on the front-end via API. Just because you're using two different languages doesn't mean you need to write the same code twice.

I prefer Laravel over Node.js because it lets me move fast.

Parting Thoughts

I could end with a note about "using the right tool for the job," but I don't feel like that's the right take away. Instead, use the fastest, most productive tool you have available to kick apps out the door quickly and get feedback from your users. For some developers and for some projects, Node.js will be that tool. However, for those who are already proficient with Laravel, Rails, or Django and want to use full-stack JavaScript to move faster, I would caution you that you might just lose a year piecing together your own framework with little to show for your investment.

Discussion (50)

Collapse
cullophid profile image
Andreas Møller

Next. JS also gives you 80% of the tooling. Why did you choose not to use it?
It seems to me that you had a chance to write a decent post about choosing tech stack, and instead you made yet another "my framework is better than your framework" post.

Collapse
tylerlwsmith profile image
Tyler Smith Author • Edited on

Thanks for reading my post, Andreas. I really like Next.js, but I disagree that it gives me 80% of the tooling I need.

Here are features that Next.js doesn't have that Laravel does:

  • Authentication
  • Authorization
  • Encryption
  • Email API
  • Password resets
  • Request Validation
  • An ORM
  • Seeding
  • Migrations
  • Testing Framework
  • CSRF Protection
  • Queues & Scheduling

Instead, Next.js provides React server-side rendering and API routes. If you were referring to NestJS, you can find my answer about why I didn't choose any of the batteries-included Node.js frameworks in the other comments.

I'm bummed that you didn't think this was a decent post and thought it was about saying one framework is better than the other. That wasn't my intention: I'm only sharing my experience about tools that let me me move fast. As I said in the last paragraph, for some developers and for some projects, Node.js will be that tool. It seems to me that you have a chance to write a decent post about choosing a tech stack, and I invite you to share your experience with the community as well.

Collapse
cullophid profile image
Andreas Møller

But you chose not to use the default options in NextJS, that's not the same as them not being there.

You move fast in php because you are familiar with php.
I move fast in js because I am familiar with JS and the JS ecosystem.

If it takes you weeks to do something in node and a weekend to do it in laravel then that has nothing to do with either the language or the framework. It's just about the ecosystem.

If you decide that you don't want to learn the JS ecosystem that is absolutely fine. I have made a similar choice about laravel and a ton of other languages and Frameworks. But I am not gonna write a post about why laravel is not as good as node/next

Thread Thread
cullophid profile image
Andreas Møller

Also. Merry Christmas 💖🎄

Thread Thread
tylerlwsmith profile image
Tyler Smith Author

Andreas,

I think you may have accidentally stumbled into the point of the article. This article is about my experience. I move fast in PHP because I'm familiar with it, which is why this is titled "Reflecting on a year with Node.js and why I should have stuck with Laravel."

The article is not titled, "Reflecting on a year with Node.js and why you should use Laravel instead."

The only concrete recommendation I give is "use the fastest, most productive tool you have available to kick apps out the door quickly and get feedback from your users." For me, that tool is Laravel.

I may not have made that clear enough in my article, so thank you for flagging that. Merry Christmas!

Thread Thread
thinsoldier profile image
thinsoldier

Andreas, please direct me to good tutorials about the JS ecosystem itself.

Thread Thread
wizzymore profile image
EPTIC

I know this is one year old. But what Andreas is saying is not making any sense, NextJS is a front-end framework, it includes nothing that Laravel offers, also, Laravel is a back-end framework, so you comparing the two doesn't even make sense. You either don't know what NextJS is or you talk about NestJS, they are 2 different ends of the world

Thread Thread
tylerlwsmith profile image
Tyler Smith Author

Wow, it's actually been exactly one year since this was published. Thanks for giving it a read!

Collapse
owenmelbz profile image
Owen Melbourne

Would be great if you could provide links to all the “nextjs” features that you’ve said are built in such as authentication, queue workers, caching layers, emailing, database?

As far as I can tell (I’ve only built maybe 3/4 nextjs projects) next mainly provides a “route -> view” with some meta/image etc sprinkles built on react, along with obvious SSR and SSG.

What I’ve taken from this post is that the nodejs eco system for full stack development is not mature enough yet to compete “feature to feature” compared to established systems like Rails and Laravel

Collapse
computamike profile image
Mike Hingley

I'd suggest looking at adonisjs as a js equivalent of laravel...

adonisjs.com/

Collapse
tylerlwsmith profile image
Tyler Smith Author

Thanks for reading, Mike!

I like Adonis. And Sails.js. And Nest.js. Loopback also looks cool.

I've never adopted any of them for a few reasons though:

  1. Lack of adoption. Every major Node.js tool has a story for integrating with Express. None of the batteries-included Node.js frameworks have major adoption, so I have to figure out how to integrate other tools myself. It also means if I run into a problem, there are far fewer resources available than Laravel.
  2. Uncertain future. I'm not sure what the projects future looks like. Adonis is mostly carried by one person. Sails is maintained by a company out of Texas. For long term projects, using Adonis feels like a risk.
  3. Lack of first-party integrations. Laravel kills it with the amount of first party integrations they have. It's a compelling reason to choose Laravel over Node frameworks, and even popular frameworks in other languages like Django or Rails.
Collapse
mgmgpyaesonewin profile image
Pyae Sone Win

Yes, also, according to my experience. I saw that sail.js is abandoned. We as maintainer of the application has such kind of fear. For laravel, it has a good ecosystem and also maintain laravel as a company. It felt much safer.

Collapse
frondor profile image
Federico Vázquez

I don't

Collapse
albertsarle profile image
Albert

I've only made a small pet project with adonisJS , and using Laravel on a daily basis I found find it very friendly.
Even I've been wondering if it would make sense to 'remake' some Laravel apps into adonis to see if nodejs has a smaller time to first byte.
Could you add mention something why you don't recommend it?

thx

Collapse
frontsideair profile image
Fatih Altinok

As someone who doesn't like PHP much, I must admit that Laravel is a well thought out framework with batteries included. I'm currently working on a full-stack project with Next.js and even though there's a lot to like about Next, a lot is also missing and I feel like reinventing the wheel every other day. I'm not complaining as I like gaining a deep perspective and prefer intentional code over magic, but I find myself looking at Laravel and Rails for inspiration a lot. The Laravel documentation also seems excellent.

Collapse
tylerlwsmith profile image
Tyler Smith Author

Next is great, but the lack of server framework features does make it more challenging. I know that projects like Blitz.js are trying to bridge the divide, but I'm always hesitant about committing to newer tech in my production code.

Collapse
frontsideair profile image
Fatih Altinok

I fully understand the hesitation. Blitz is awesome, but it's young and missing many crucial features of existing web frameworks at this time.

I also checked Adonis from the comments and it seems like an analog of Laravel, even the documentation is structured similarly. But on the other hand I'd expect a JavaScript framework to fully utilize native frontend libraries, where it would really shine.

Thread Thread
tylerlwsmith profile image
Tyler Smith Author

I'm really interested to watch if Adonis ever takes off in a big way. Of all the frameworks I've seen it's the one that is most appealing to me.

Collapse
sroehrl profile image
neoan • Edited on

I appreciate this post! Looking back at the past 5 years, my life has also been parted between PHP and node, depending on the team. And even though I prefer Vue instead of jQuery and neoan3 instead of Laravel, the gist of what you are saying remains true: the node environment simply hasn't been able to provide the same experience and becomes messy way too easily. As many others, I am waiting for deno to pick up some of the mess, but especially considering the hate PHP gets, one can't help but wonder why node is so popular.

Collapse
tylerlwsmith profile image
Tyler Smith Author

Thank you for reading! I'm quite a Vue fan myself. I'm also a fan of Node, I just wish that it didn't get hairy so quickly. Here's to hoping that one day it will be better. Until then, PHP still rules 80% of sites on the Internet so I'm comfortable where I'm at 😁

Collapse
amitavroy7 profile image
Amitav Roy

Hey Tyler, I completely get what you are saying. Actually I have very similar feeling. The only difference is, I have worked with Laravel for more than 5 years and now I am told to shift to Node. So, you can understand, it's even more hard for me.

Anyways, if you want then I would suggest you give Adonis JS a shot. It's a great Node based Framework with a lot of these things already there.

Yes, the framework is new and that's a risk. However, when doing something in node using completely own code - Adonis is still a good starting point I think.

Collapse
tylerlwsmith profile image
Tyler Smith Author

Thank you for reading my post, Amitav.

You've convinced me: I'm going to give Adonis a real shot on a personal project. Version 5's TypeScript support is really compelling.

Collapse
amitavroy7 profile image
Amitav Roy

Yes, the ground up TypeScript support is very compelling. Also, the person who is behind the project is now full time on it. So, I am sure this is going to pick up a lot more.

Cheers and a very happy new year to you.

Thread Thread
tylerlwsmith profile image
Tyler Smith Author

I didn't know he was full time now–thanks for the information. Happy new year!

Collapse
const_require profile image
Sean • Edited on

Great read. 👍 Just out of interest why did you decide to go for Node and its ecosystem in the first place? Particularly if you already had experience with Laravel. Was there something that you found lacking in Laravel that you could only leverage through Node? Or was it purely cosmetic?

Collapse
tylerlwsmith profile image
Tyler Smith Author

Thanks for reading the article, Vero!

The biggest feature that drew me to server-side JavaScript was code-sharing. I liked the idea of being able to share TypeScript interfaces on both the server and the client. Now that I'm using Laravel as my back-end again, keeping REST API changes in sync with the front-end interfaces is a challenge.

Server-side React rendering and fear of missing out were the other reasons I used Node. I'm glad I gained a new skillset in the process, and I'm sure it'll come in handy someday.

Collapse
circlecurve profile image
CircleCurve

If rest api changes in sync that is your problem, I think you can take a look of graphql. GraphQL is a schema that define a standard of how the client communicate with your server. All api will consolidate with one url and data format is like a graph
Something like that

{
   user : 1 {
       id 
       name
   }
}
Enter fullscreen mode Exit fullscreen mode

If your server side schema change, your client don't need to worry about more calling more and more api.

Thread Thread
tylerlwsmith profile image
Tyler Smith Author

Thanks for the suggestion, CircleCurve!

I've used client-side GraphQL from a React app before. It was fine.

On the server, it sounds like it would add a lot of complexity outside of simple CRUD apps. REST API endpoints have a predictable code execution path and can be separated into distinct concerns. I don't know how that looks on the server for GraphQL, especially when performing validations, triggering side-effects, etc.

I know it's possible, and maybe it's easier than I'm thinking. It just feels like I'd be moving a lot of complexity from the front-end to the back-end, and since I'm already working on both, I don't see a big advantage.

If I were on a team of 20+ engineers with people only working on the front-end and only working on the back-end, GraphQL would be extremely appealing though.

Collapse
swina profile image
Antonio

I appreciate your post. Btw you should check Feathersjs as node based framework for realtime apps and rest api. Many features out of the box that help you to focus on the app develoment then they develop another node-express backend from scratch.

Collapse
tylerlwsmith profile image
Tyler Smith Author

Thank you for the feedback Antonio, I'll check it out!

Collapse
blaazoon22 profile image
blaazoon22

I use symfony and laravel. If you want jet speed in developing go for symfony. Symfony would create a crud system with a single line of code on your from command line. This is after you have created an Entity which holds your crud properties and methods (getters and setters). Symfony is 3x faster than laravel.

For me Node and express js is a time killer.

Collapse
vladi160 profile image
vladi160

JWT and cookie based auth are different things. It is like a car or a pizza and the tech stack doesn't matter for which1 to choice/use.
The encryption algorithm is the same for all technologies.
Require/import, I am not sure this is a problem at all. May be, when you want to share a global data like constants. Also, there is a window, which on the server is undefined.

Sometimes bad docs and no supported packages - yes.

NodeJS is a different kind of thinking/culture. It is not about the language, only.

Collapse
tylerlwsmith profile image
Tyler Smith Author

Hey, thanks for giving my article a read. I agree with you that Node.js has a different culture and thinking, and it's definitely not just about the language. Node a great option for many developers.

Collapse
Sloan, the sloth mascot
Comment deleted
Collapse
tylerlwsmith profile image
Tyler Smith Author

Thank you for reading the article, Hammed.

Nowhere in this article did I suggest that Laravel was better than Node. I said that I prefer Laravel over Node.js because it lets me move fast.

On most of my projects, I'm a solo developer responsible for design, front-end & back-end development, deployment, and maintenance. I typically get about two weeks to build a functional MVP from scratch by myself. Laravel's features and familiarity lets me move fast which is why I prefer it. That doesn't mean that Laravel is better.

Other developers move faster in Node, or they just like Node more. I'd encourage those developers to continue using Node.

Collapse
gcnu profile image
seenu

Can you write other way article? i am really interested.

I am not trying to challenge/insult you, a genuine request.

Collapse
Sloan, the sloth mascot
Comment deleted
gcnu profile image
seenu

i want to know what are those ugly parts are, anyways....

Thread Thread
bennettblack profile image
Bennett

As do I. This isn't an article about Node's weaknesses. I think Hammed is taking it as such.

Collapse
dietrichg profile image
Dietrich G

It's not too bad if you structure it properly. Just as with jQuery, PHP etc. I came from both of those backgrounds 15 years ago and never looking back.

Collapse
tylerlwsmith profile image
Tyler Smith Author

I'm pretty happy with how my Node apps are structured, my code is clean and maintainable. I just have to spend too much time implementing commodity features like authentication, authorization, password resets, data migrations, seeding, social login, etc. With Laravel, I get those for free out of the box.

If the Node community ever gets a batteries-included framework that is as popular as Laravel or Rails, I'll be happy to use that. I like writing JavaScript a lot more than PHP.

Collapse
guledali profile image
guledali

Absolute true, I couldn't agree more @tylerlwsmith

To me it's mind boggling why so few companies are using Rails

Collapse
tylerlwsmith profile image
Tyler Smith Author

Thanks for reading, Guledali. I just started learning the basics of both Ruby and Rails a few weeks ago. What a nifty language and fantastic framework. I'm hoping to get the chance to do big projects with it in the future.

Collapse
nicodinh profile image
Nicolas Azari

I don't understand why you chose a minimalist framework like Express instead of an advanced framework like NestJS to make a REST api.

Collapse
tylerlwsmith profile image
Tyler Smith Author

Hey Nicolas, thanks for checking out the post. I use Express because it's the most widely adopted Node Framework and it's a project of the Open JS foundation. If I build anything important using Express, I have confidence it'll still be around in five years.

I'm generally a little hesitant to use NestJS, Adonis, Sails, Loopback or other batteries-included Node frameworks for the same set of reasons:

  1. Lack of adoption. Every major Node.js tool has a story for integrating with Express. None of the batteries-included Node.js frameworks have major adoption, so I have to figure out how to integrate other tools myself. It also means if I run into a problem, there are far fewer resources available than Laravel.
  2. Uncertain future. I'm not sure what the projects future looks like. Adonis is mostly carried by one person. Sails is maintained by a company out of Texas. For long term projects, using Adonis feels like a risk.
  3. Lack of first-party integrations. Laravel kills it with the amount of first party integrations they have. It's a compelling reason to choose Laravel over Node frameworks, and even popular frameworks in other languages like Django or Rails.

I'm also just faster getting up-and-running with Laravel. It has things like password resets built into the framework's first-party packages, which is a feature I don't want to have to implement myself.

All of that said, if the Node community converges on NestJS as its go-to framework the way that the Ruby community has converged on Rails, I can see myself going all-in on NestJS and full-stack JS.

Collapse
coopercodes profile image
🧸 🏳️‍🌈 cooper-codes 💻 🎮

This hit me at the right time, thanks for this article.

I’ve just accepted my first real dev job and it’s a Laravel/React architecture.

I’m now really excited for it.

Collapse
tylerlwsmith profile image
Tyler Smith Author

Congratulations on your new job, that has to be an amazing feeling. Laravel + React is a killer stack: you're going to be able to build some really cool stuff with it.

Collapse
devdammy profile image
Dammy Ola

Great Article

Collapse
tylerlwsmith profile image
Tyler Smith Author

Thank you for reading it, Dammy! I'm glad you liked it.

Collapse
readymadecode profile image
Chetan Rohilla

Hi! Yes absolutely right but i have one project in laravel and i need to move this to node.js for my client. Can you please suggest me how can i do this