DEV Community

Haseeb Burki
Haseeb Burki

Posted on • Updated on

Migrating API from Laravel to NestJS

I want your opinion

I've been working as a full-stack developer on mobile and web-based application backed by an API built in Laravel for 2 years.

Fast forward to today we have 3 developers (excluding myself) working on the same code.

Recently I've been seriously considering migrating the API to JavaScript. After doing some research I decided on NestJS.

When I started looking at javascript (NodeJS) I was disappointed. None of the backend libraries or frameworks offered as much as Laravel does. I had to setup up very trivial things like server-side validation, dependency injection, error logging, etc. things which Laravel offers right out of the box. NestJS removed most of these concerns.

Pros of Migrating to NestJS

  • I have a personal desire to shift my work to JS.
  • Migrating backend to JS closes the language barrier between frontend and backend devs.
  • I can handle testing both frontend and backend with Jest.
  • There are a lot more developers for Node and JS than for Laravel.
  • JS ecosystem (npm) is much better than PHP's ecosystem.
  • Node seems to have a leg up in terms of performance.
  • Unfortunately Laravel is cursed by its language of choice (PHP). This scares away a lot of potential new developers.

Note that I run a team and have to retain my employees. I also need to consider what resources are available in case I hire more employees.

Cons of Migrating to NestJS

The only issue I have is the time and effort I will have to put in to migrate all our work to a new framework. I (and my team) are comfortable with Laravel but want to migrate to NestJS.

I just wanted to get more opinions about whether migrating is a good or bad idea? And do you think it will be worth it in the long run or not?

Top comments (10)

deepslam profile image
Dmitry Ivanov

I've worked with Laravel for about 3 years and I love it. But exactly as you, I wanted to work with Node.JS. I had some approaches to learn Node, but I didn't really have a project, to begin with.
Right until now, today, I need to create an API. At first, I tried Loopback, but it seemed too complicated for me and has a mess in its documentation.
And then I looked at NestJS, and I like it. But working with it I realized how far and how beautiful Laravel really is in comparison with NestJS (I suppose with any JS framework).
Those TS decorators look really ugly (maybe I just didn't get used to working with them, it's just a first glance).
But I'm keeping on just because JS ecosystem is better and I want to work with it more.

hzburki profile image
Haseeb Burki

Before you start, take a look at I actually found it a couple of days ago. I really liked NestJS and shipped a v small service to production but I decided against using it for my main API.

The routing it provides really bugs me and is not at all suitable for my current API structure which I do not want to change. Another thing I don't like is the server-side validation and error handling. Laravel has really ruined me :P

Try FoalTS it's relatively simple and much more flexible. I have not had the time to try it out fully, but I think it will be a better fit (for me) than NestJS.

deepslam profile image
Dmitry Ivanov

Thank you so much! I'll have a look :)

prashanth1k profile image
Prashanth Krishnamurthy

I don't have a lot to say, but here goes -

I moved from Laravel to Node, and it was not exactly joyful. I was/am using AdonisJS - feels like Laravel in Node world, so the migration was a bit easier.

IMO Laravel has quite a bit of tools + articles + people who were making development easier. Node + Javascript has a huge community but one tends to get confused by the many options.

Looking back: I should have probably moved something small, evaluated how we fare and incrementally take up more. I will certainly not take up more complexity at the beginning - for e.g. move to a headless CMS + GraphQL while I was in Laravel + the good ol' Rest.

Then - there is also a matter of cost. Shared servers can run Laravel and cost next to nothing while being acceptable for smaller applications. NodeJS on low-end VPS is not exactly expensive but things tend to add up. If you are in this situation - be mindful of the ongoing maintenance (patching OS, web servers, etc.)

hzburki profile image
Haseeb Burki

Thanks for the reply. I have a big system that I want to move to NestJS. I have a website in Gatsby, 3 web portals and a RN app.

Everything including the database is hosted on AWS and I need to be able to scale. Also I love Laravel its a great framework you're right about the support and articles but it isn't really known to be performant at scale.

That, along with the fact that devs here run from PHP and tend to go towards JS technologies is why I'm considering moving to NestJS.

I do like the idea of porting something small. I had the exact same idea in mind about porting the portal we use for in-house use.

khacnha profile image
Khac Nha

@hzburki have you done this yet?
I am also planning to do this.
and am looking to see if there are any good ideas.

Nestjs connection problem with existing Database created from Laravel ok? I am worried about this problem and authentication problem with users table created with laravel.

adilismail621 profile image
Adil ismail

Unfortunately Laravel is cursed by its language of choice (PHP)"
Why do u say this ?

hzburki profile image
Haseeb Burki

It's mainly because of PHP's reputation in the dev community. As a developer who is constantly looking for talented and hard working developers, I find it difficult to find people who are interested in working on PHP. Developers nowadays want to move towards the JavaScript ecosystem such as Node and React etc.

qodeboy profile image
Pavel Sheiman

It's not just reputation. It's a fact. Once you're in the event-loop you can't get back to PHP's forking. It's like going from dedicated lane back to dial-up internet.

I'm 10+ years in PHP development, and 1+ year in pure JS/TS development and I can feel the difference on my own skin.

Swoole and RoadRunners try to solve this, but this is not going to work with mid-to-large sized projects, as compatibility is really poor and there is a lot of issues.

PHP have to rethink legacy compatibility and make a big jump into new age to keep up with JS ecosystem progress. Or it's dead eventually.

klobusnik profile image
Matej Klobusnik

what was the result? Have you migrated at the end? How much effort did it take? Was it worth it?