How does Node.js compare to a traditional MVC platform like Spring?

By: ( +David Herron; Date: 2016-04-27 23:07

Tags: Node.JS » Java » Spring

Node.js is a young software development platform. It's only about 6 years old, and many software developers are still unsure about where Node.js fits into the landscape. It's JavaScript, which many people pigeon-hole as a browser language, but Node.js doesn't run on browsers but on servers. The question above illustrates a fundamental confusion about what Node.js is, and its role in the world, because it is not an "MVC" but a complete programming platform.

What is Node.js? It's a general-purpose programming platform using JavaScript as the language, and a runtime full of asynchronous file-system and network I/O functions. It supports an event-oriented model of programming, using JavaScript features like anonymous callback functions and Promise objects to their fullest. It is a lightweight system that eschews traditional thread-based architectures, and instead relies on a single threaded event-loop architecture. The combination produces a system that can sustain very high transaction throughput, and is very easy to program for.

Spring is kind of the antithesis to Node.js, and it may be that Node.js's popularity is due to many programmers tired of the over-the-top nature of the Spring ecosystem. What I mean is that Spring throws in dozens of kitchen sinks worth of features to make an extremely complicated system that tries to be the be-all-end-all. To be fair, many of the kitchen sinks I refer to are not Spring per-se but other projects like Hibernate and Java Persistence. Through Spring DAO objects, a specific MVC (Model View Controller) model is strongly encouraged. The system is written in Java, on Java EE appservers like Tomcat or Glassfish. These appservers are themselves large hairy beasts full of complexity, and strongly dependent on a thread-based architecture.

Maybe that characterization of Spring will offend some. Consider that 10+ years ago I worked at Sun in the Java SE team, and was routinely writing blog posts on my ( blog defending Java as being superior to JavaScript. Today my opinions have flipped because of my experience with Node.js, and the ease of programming it offers. I currently am employed writing Spring code ... the other day I needed to return a JSON object to an HTTP POST request, and therefore needed to create a JSON Mapper object -- because -- uh -- Spring makes you do all kinds of excess work to get anything done. Namely, I needed to create a Java class with a couple dozen fields. After using Eclipse to auto-generate the Constructor, the Getters and Setters, and the hashCode and toString and equals methods, the class weighs in at almost 600 lines of code. All that just to manage a couple dozen fields.

By contrast in Node.js the same task - returning JSON from an HTTP POST request - would take a handful of lines of code. Rather than be burdened with implementing a 600 line monstrosity just to return some data, in Node.js you simply pass an anonymous object (because JavaScript supports such things) to a method that formats objects as JSON, and QED the thing is done as quick as can be.

This was a slight detour from answering the question, but it points in the direction I want to take. Namely - Node.js is full of low computational cost solutions that are easy to code, easy to maintain, and straightforward. Spring, on the other hand, is full of heavy-weight solutions because what seems to me as a mindset that Spring (and the whole Java ecosystem) goes beyond the pale to solve every last problem that exists.

Node.js does not have any opinion about how you organize your code. It doesn't care where the source files are located, what's in them, whether you define proper classes, whether you use anonymous objects, whether the capitalization of method or variable or class names is correct, whether you use the model-view-controller paradigm, and on and on and on. Its role is to simply provide a base set of runtime modules, and an excellent JavaScript engine sourced from the Google Chrome team. You make of Node.js what you will.

Spring forces you to use Java Beans DAO objects, and to organize HTTP responses around Controller classes, to use lots of XML files to describe things that should be written in code, and on and on. The Java Bean model relies on Java annotations that perform magic functions where you write a "simple" Java class sprinkled with annotations. The system then magically instantiates these Beans somehow and on and on. It's really nauseating thinking about how many layers of abstraction are going on, and the computational/complexity overhead entailed by something as innocuous-seeming as the @Autowired annotation. How does Spring magically figure out how to find the value it is autowiring into place? And why is it so hard to just explicitly write the code in the first place?

There are MVC frameworks written on top of Node.js. The better question would have been - how does Express (or another framework) compare against Spring? But even that's not good since Express itself is not MVC-oriented.

In any case, the frameworks available for Node.js tend to be streamlined, easy to program, straightforward, etc. The JavaScript language helps a lot with this since it is so much easier to program in JavaScript than in Java.

Way-back-when, what was my argument that Java is superior? The Java language actively helps you catch certain kinds of errors because of strict type-checking of all kinds of things. Fields in objects, method parameters, and basically everything else you touch has to be rigidly and correctly typed. In JavaScript you're using anonymous objects and anonymous functions all over the place, with no data typing, and it would seem like a nightmare of potential problems.

But the impact of strict typing is an onerous burden of coming up with data types for everything you touch. What if you have two methods communicating data -- data that will ONLY be exchanged PRECISELY between these two methods? In Java you still have to define a Class to store that data, and depending on the shape of that data the Class might be complex. In JavaScript you simply throw the data into an anonymous object, and make sure the two functions are written correctly to deal with the object. An example is the JSON Mapper I mentioned earlier -- 600 lines of code to manage an object with 20 fields. Bah.

In Express/Node.js it's this simple

  field1: value1, field2: value2, field3: value3, ...

The result is the same - JSON sent to the caller. Which is easier to write, easier to maintain, easier to understand?

« Is Node.js / Express scalable? How to grow Node.js app deployment to handle more traffic? Node.js 4.0.0 is out - quick tip for use while testing compatibility »
2016 Election 2018 Elections Acer C720 Ad block Affiliate marketing Air Filters Air Quality Air Quality Monitoring AkashaCMS Amazon Amazon Kindle Amazon Web Services America Amiga and Jon Pertwee Android Anti-Fascism AntiVirus Software Apple Apple Flexgate Apple Hardware History Apple Hardware Mistakes Apple iPhone Apple iPhone Hardware April 1st Arduino ARM Compilation Artificial Intelligence Astronomy Astrophotography Asynchronous Programming Authoritarianism Automated Social Posting AWS DynamoDB AWS Lambda Ayo.JS Bells Law Big Brother Big Data Big Finish Big Science Bitcoin Mining Black Holes Blade Runner Blockchain Blogger Blogging Books Botnets Cassette Tapes Cellphones China China Manufacturing Christopher Eccleston Chrome Chrome Apps Chromebook Chromebox ChromeOS CIA CitiCards Citizen Journalism Civil Liberties Climate Change Clinton Cluster Computing Command Line Tools Comment Systems Computer Accessories Computer Hardware Computer Repair Computers Conservatives Cross Compilation Crouton Cryptocurrency Curiosity Rover Currencies Cyber Security Cybermen Cybersecurity Daleks Darth Vader Data backup Data Formats Data Storage Database Database Backup Databases David Tenant DDoS Botnet Department of Defense Department of Justice Detect Adblocker Developers Editors Digital audio Digital Nomad Digital Photography Direct Attach Storage Diskless Booting Disqus DIY DIY Repair DNP3 Do it yourself Docker Docker MAMP Docker Swarm Doctor Who Doctor Who Paradox Doctor Who Review Drobo Drupal Drupal Themes DuckDuckGo DVD E-Books E-Readers Early Computers eGPU Election Hacks Electric Bicycles Electric Vehicles Electron Eliminating Jobs for Human Emdebian Encabulators Energy Efficiency Enterprise Node EPUB ESP8266 Ethical Curation Eurovision Event Driven Asynchronous Express Face Recognition Facebook Fake Advertising Fake News Fedora VirtualBox Fifth Doctor File transfer without iTunes FireFly Flash Flickr Fraud Freedom of Speech Front-end Development G Suite Gallifrey Gig Economy git Github GitKraken Gitlab GMAIL Google Google Adsense Google Chrome Google Gnome Google+ Government Spying Great Britain Green Transportation Hate Speech Heat Loss Hibernate High Technology Hoax Science Home Automation HTTP Security HTTPS Human ID I2C Protocol Image Analysis Image Conversion Image Processing ImageMagick In-memory Computing Incognito Mode InfluxDB Infrared Thermometers Insulation Internet Internet Advertising Internet Law Internet of Things Internet Policy Internet Privacy iOS iOS Devices iPad iPhone iPhone hacking Iron Man iShowU Audio Capture iTunes Janet Fielding Java JavaFX JavaScript JavaScript Injection JDBC John Simms Journalism Joyent jQuery Kaspersky Labs Kext Kindle Kindle Marketplace Large Hadron Collider Lets Encrypt LibreOffice Linux Linux Hints Linux Single Board Computers Logging Mac Mini Mac OS Mac OS X Mac Pro MacBook Pro Machine Learning Machine Readable ID Macintosh macOS macOS High Sierra macOS Kext MacOS X setup Make Money Online Make Money with Gigs March For Our Lives MariaDB Mars Mass Violence Matt Lucas MEADS Anti-Missile Mercurial MERN Stack Michele Gomez Micro Apartments Microsoft Military AI Military Hardware Minification Minimized CSS Minimized HTML Minimized JavaScript Missy Mobile Applications Mobile Computers MODBUS Mondas Monetary System MongoDB Mongoose Monty Python MQTT Music Player Music Streaming MySQL NanoPi Nardole NASA Net Neutrality Network Attached Storage Node Web Development Node.js Node.js Database Node.js Performance Node.js Testing Node.JS Web Development Node.x North Korea npm NSA NVIDIA NY Times Online advertising Online Community Online Fraud Online Journalism Online News Online Photography Online Video Open Media Vault Open Source Open Source and Patents Open Source Governance Open Source Licenses Open Source Software OpenAPI OpenJDK OpenVPN Palmtop PDA Patrick Troughton PayPal Paywalls Personal Flight Peter Capaldi Peter Davison Phishing Photography PHP Plex Plex Media Server Political Protest Politics Postal Service Power Control President Trump Privacy Private E-mail server Production use Public Violence Raspberry Pi Raspberry Pi 3 Raspberry Pi Zero ReactJS Recaptcha Recycling Refurbished Computers Remote Desktop Removable Storage Renewable Energy Republicans Retro Computing Retro-Technology Reviews RFID Rich Internet Applications Right to Repair River Song Robotics Robots Rocket Ships RSS News Readers rsync Russia Russia Troll Factory Russian Hacking Rust SCADA Scheme Science Fiction SD Cards Search Engine Ranking Search Engines Season 1 Season 10 Season 11 Security Security Cameras Server-side JavaScript Serverless Framework Servers Shell Scripts Silence Simsimi Skype SmugMug Social Media Social Media Networks Social Media Warfare Social Network Management Social Networks Software Development Software Patents Space Flight Space Ship Reuse Space Ships SpaceX Spear Phishing Spring Spring Boot Spy Satellites SQLite3 SSD Drives SSD upgrade SSH SSH Key SSL Stand For Truth Strange Parts Swagger Synchronizing Files Tegan Jovanka Telescopes Terrorism The Cybermen The Daleks The Master Time-Series Database Tom Baker Torchwood Total Information Awareness Trump Trump Administration Trump Campaign Twitter Ubuntu Udemy UDOO US Department of Defense Video editing Virtual Private Networks VirtualBox VLC VNC VOIP Vue.js Walmart Weapons Systems Web Applications Web Developer Resources Web Development Web Development Tools Web Marketing Webpack Website Advertising Website Business Models Weeping Angels WhatsApp William Hartnell Window Insulation Windows Windows Alternatives Wordpress World Wide Web Yahoo YouTube YouTube Adpocalypse YouTube Monetization