DEV Community

kim-jos
kim-jos

Posted on

Express vs Nest

I had the opportunity to create a simple backend program with CRUD operations using ExpressJS though I've been using NestJS. I personally enjoyed using NestJS a lot more than ExpressJS because 1) ExpressJS doesn't provide a structure for your project and 2) NestJS requires less set up.

1) Structure
I like the fact that NestJS provides a set structure for all your projects. If you see NestJS projects you'll notice that almost all their projects are structured very similarly. But ExpressJS provides a lot of freedom for the structure of your projects. I think that there is a best practice but if you see 100 different ExpressJS projects I can guarantee that there will be more variety in project structures when compared NestJS.

I guess that freedom is good for others but bad for people with little experience. Let's get into the details of how it is different. Let's say that there are two different modules: User and Game. Nest structures this by putting all the User related files into a folder called User. That module would have a controller, service, repository, entity, and other testing files. ExpressJS, based on my personal experience, structures their projects according to its function. For example, all the controllers are grouped together and other routers are grouped together, etc.

Nest Controller == Express Router
Nest Service == Express Controller
Nest Repository == Express Repository
Nest Entity == Express Model

1) Set up
Another reason I enjoy using NestJS is because everything is nicely set up for you. When I started my project there were so many errors in ExpressJS and I wasted too much time trying to figure it out. NestJS also provides a great CLI which makes it easy to get started because all the boiler plate code is already created for you.

Although learning dependency injection, inversion of control, and other weird crazy words is difficult in the beginning NestJS really helps users focus on the project at hand instead of the set up which is really convenient for me personally.

Top comments (0)