The Goal of This Article
This is a not so technical comparison (you can find more specific tech comparisons elsewhere). I just wanted to outline how it feels to develop web applications in Node.js when you are a Java developer by trade.
So please remember, this article is full of personal opinions.
Before starting, I outline a few premises:
What I’m Trying to Compare
I would like to highlight some of the differences that are perceived when developing an application based on the Node/Express stack compared to one based on Spring Boot.
Why I’m Comparing These
TL;DR: After completing a contracted project, I decided to test another ecosystem to check if it could avoid some of Java’s most criticized points.
One of my last customers was a company that was creating a crypto exchange (yes, quite a common thing in today’s market, but not so common for an Italian based company). They contracted me to join their teams (three different developing teams) and help them build their platform. I mainly developed microservices for authorization and authentication, core transactions processing, and other stuff like customers’ KYC microservices and code libraries shared among different microservices.
That was a big and interesting project.
But during discussions with other teams and people I often heard critiques of Java-based web development in favor of Python or Go. Some of the critiques on Java that the other languages seemed to not suffer from were:
I must be honest, sometimes I think that in 2019 all of the five points above are really reasonable critiques so I wanted to experiment with self-funded projects to test some other technologies.
Since I needed to do web development and not necessarily microservices-based projects, after a quick (really quick) look at GO, I decided against that language. I think it is a great language (from what I read) but it’s not the right tool for my current projects.
I leave to you all the observations regarding dynamic typing, which, in my opinion, isn’t a big deal.
Node.js Is Single-Threaded
Okay, this is one of the most “shocking” things for a Java developer. But the shock vanishes after a few moments. You should consider that everything runs on a single thread (on any Java web app you have multiple threads) and that callback functions (asynchronous functions) are queued and executed when it is better to execute them, but all the code runs on a single thread (the key to Node.js’s speed and low memory consumption). From a Java developer’s point of view, this means:
The JS Equivalent to the Spring Boot Ecosystem: Express.js, Passport.js, Sequelize
If we limit the comparison to the MVC web application part only, Spring Boot is definitely fabulous: light and fast, complete and extremely configurable. From this point of view, a Java developer does not feel any major shortcomings compared to what the counterpart of Express.js offers.
Express.js also offers the same potential. One thing that, depending on personal taste, can be more appreciated or not is the routing: instead of being defined at the level of Java annotation it is defined at the level of routing files.
More generally, Spring Boot indicates a very precise way to organize code into packages (models, services, controllers) while in an Express.js context there are no such guidelines. Nevertheless, it is possible to reapply a similar code structure and there are often projects where the code is structured in a similar way to a Spring Boot project.
ORM in Java has always been, from my point of view, the Achilles heel of Java applications. The Java standard is roughly Hibernate (despite the various alternatives, however widespread, such as Jooq and MyBatis), while, for the JS world related to relational DBs, the most popular library is Sequelize.
Hibernate vs. Sequelize
TL;DR: Hibernate is still the most complete, mature, and versatile solution, but at a very high cost! Sequelize may cover 90% of your use cases.
I don’t hate Hibernate, but I surely don’t love it. It’s over engineered, slow, and complicated. It’s like an elephant. It can, however, do anything with any supported DB. On the contrary, Sequelize is small and simple but can’t manage all use cases.
Some of the things I discovered through the use of Sequelize:
There are also some things that I love in Sequelize, like the easiness to create queries at runtime (that’s a breeze, you can compose a JSON object at runtime and pass it to the query engine). Try to do it while creating a JPQL query or consider how overcomplicated it is to do with certain criteria. Honestly, using Hibernate and Spring Data JPA while trying to dynamically filter a query at runtime by some fields is a pain in the ass, while it is really easy (as it should be with any framework/language) to do in Sequelize.
Another aspect where Sequelize shines in respect to Hibernate is when you hit some hard cases and need to do a native query: both of them let you execute native queries, but, honestly, it is a lot simpler to convert the results to their models in Sequelize than in Spring Data JPA/Hibernate.
And I’m not talking about startup time: introducing Hibernate adds seconds to boot time, while Sequelize is quite immediate.
As a final consideration, it’s quite obvious that:
BigDecimal class are perfect for that scope).
A thoroughly researched list of top NodeJS development companies with ratings & reviews to help hire the best Node.JS developers who provide development services and solutions across the world. List of Leading Node.js development Service Providers...
NodeJS Development Company-Hire Node JS developer from the most prominent NodeJS development company, Mobiweb and get remarkable Node.js app development services.
You have to hire Node JS developer from prestigious and expert Node JS development company Mobiweb Technologies. They are tech enthusiasts with new and latest programming ideas, web development technologies and industry trends.