DEV Community

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

Tyler Smith on December 23, 2020

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, ...
Collapse
 
lexiebkm profile image
Alexander B.K.

"Lack of Adoption"
In job requirements I have seen, I have never seen an explicit mention of Node.js frameworks. They mention Node.js but very few mention Express or Nest.js, let alone the likes of Adonis.js.
Whereas, Laravel is very often mentioned in the requirements for PHP developer. This is the main reason I use Laravel, although still have to explore several things on it and PHP too.
Node.js is still interesting, though.
Still, other alternatives are waiting for me : Go (with or without framework), C# + ASP.net, Java (with Spring or JEE).

Collapse
 
tylerlwsmith profile image
Tyler Smith

Go + the Buffalo framework is on my list of things to learn this year.

Collapse
 
lexiebkm profile image
Alexander B.K.

For Go framework, I think I will pick among these three : Gin, Fiber or Echo.

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 • Edited

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

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

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

Thread Thread
 
wizzymore profile image
EPTIC

Funny stuff, now what i said is not really true anymore.

Since the new router in Next.js and React Server Components, next.js can really be considered a back-end framework now.

Kudos to the Next.js team for making next.js what php was able to do since day one of the release, but, with included reactivity, which i still don't know if it is good or not. The line of separation between front-end and back-end are now separated by a "use client" text at the top of the file. Weird times we live in

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

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
 
abhay07 profile image
Abhay Srivastav • Edited

Next.js is a front end framework specifically created for creating server side rendered web application.
If you want to write backend in js, you should not rely on Next.js for that. Use Express.js + Mongodb/Express.js + SQL with Node.

Collapse
 
tylerlwsmith profile image
Tyler Smith

Hi Abhay, thanks for reading the post!

While Express/Mongodb would give me a back-end server and data persistence, it would still require quite a bit of hand-wiring compared to a batteries included framework like Laravel. This stack would also leave me with many decisions to make. For example:

What ORM or DB driver do I use? Should I use cookie auth or JWT? What encryption algorithm is best? What library should I use for data validation?

There are back-end JS frameworks that have answers to these questions, but it always feels like a risk using any of them. Compared to other languages, JavaScript frameworks seem especially prone to breaking changes, fast trend cycles, and maintainers abandoning projects.

Laravel feels like a great solution to these problems. Other developers may prefer Node.js. That's totally fine! My only recommendation is choosing tools that let you move quickly. For me, that's Laravel. For many other developers, that may be Express and Mongo 🙂

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

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

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

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

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

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

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

Collapse
 
const_require profile image
Sean • Edited

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

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

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
 
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
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
tylerlwsmith profile image
Tyler Smith

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....

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

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

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

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
 
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

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

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
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
tylerlwsmith profile image
Tyler Smith

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

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

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

Collapse
 
ttjordan81 profile image
Timothy Jordan

My team went from Laraval to NodeJS. I agree, the starting point was hard. I'm lucky enough to have 4 other dev but we built and pieced things together in a reasonable time.

Once we got past all the shit that Laraval give you, the 80%, we started picking up the pace. One dev that's been developing in .NET for 20+ was shocked how much little code was used to build a functional app.

I'm thinking of creating an open source skeleton version of the app, that just has everything you need to get started. Authentication, login, User Management, controller, model CRUD, routing, DB Migration, Middleware, etc.

It has Tailwind, and VueJs web ui frontend.

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