.NET vs Node.js
Coder, Blogger, .NET expert
Hello there, you might be here because you wish to code up your shiny brand new blog, start writing articles that will captivate your readers and earn you a following, perhaps you had an amazing idea for a brand new web application that will change everything or maybe you simply wish to create simple website to present yourself with and can't be bothered with Wordpress or PHP.
But the problem you face is one that most developers have these days.
Which DAMN techstack to use???
We are spoiled with choices like never before in the history of development. There are many web development libraries, programming languages and frameworks but in this case we'll only focus on Node.js and .NET Core specifically ASP.NET
Both of these technologies have firmly established themselves in the world of web development over the last few years. Both pride themselves on performance and scalability, both have groups of devoted fans and highly opinionated developers behind them.
In this article we'll discuss how they are alike and how they are different, where their respective strengths lie and where they might experience shortcomings and hopefully along the way I can help you make up your mind or at least ease your decision a bit.
I have a confession to make! I'm a .NET developer and I might have a bit of a bias towards my favorite framework. However the purpose of this article is not to compare which of the two is better but simply to point out the differences between the two in an objective, honest kind of way. Most of us developers love our respective technology tribes that we have established. But there will hopefully be none of that in here.
Here's another confession: most of these points will most likely start with 'it depends'... and then a short explanation on how different people have different experience levels and different preferences. Well... This point depends heavily on your pre-existing knowledge. ASP.NET comes with a premade project/file structure, premade boilerplate and some nifty examples on how to use the MVC pattern.
To a complete beginner this could be incredibly helpful as it provides an easy entry point into an architecture that is widely considered an industry standard, while to others that prefer to learn as they go it could be a hinderance or downright confusing. Node.js with express on the other hand is as barebones as it goes.
You install the express module via the NPM and then you're on your own, what pattern your choose, how you structure your project and so on is on you.
To a complete beginner or even an experienced developer this may be confusing but it's nothing that a google search or a look at the documentation couldn't fix.
Obligatory it depends on your pre-existing knowledge and experience.
Both languages are hugely popular and therefore provide you with an ocean of knowledge one google search away. As I've mentioned above ASP.NET does come with premade project templates that allow you to jump straight into developing your web app. However a quick search reveals a ton of Yeoman generators
that you can use freely.
But hey that's just the starting phase. How about the actual development time?
I firmly believe that I can create a fully functional webapp or RESTful API faster in ASP.NET than I could in Node.js. This has a lot to do with the tooling that Microsoft has provided and the fact that most of the most important modules, plugins, nuget packages in ASP.NET were all created by the same company.
Which means there's less surprises, method names don't suddenly switch from camelcase to snakecase and so on. With Node.js that is not the case as often each node module is written by a different developer. These developers may have different preferences, ideas and standards. This in turn makes me consult the documentation more often than I would like, sometimes even on stuf I have done a million times. Because better safe than sorry right?
As I've mentioned in the point above, ASP.NET most used and important nuget packages are all developed by Microsoft, which means they will always work together and always stay concise. Where as most node modules are written and maintained by different developers with different philosophies.
This obviously has a big effect on the stability of your webapp. One day you could decide to update your project and all it's dependencies only to discover they don't work well together anymore or that a method you used all over your project has been deprecated or even renamed.
This can ruin anyone's day, I know I wasn't too happy when it happened to me.
Furthermore these developers can at anytime stop maintaining their modules and leave you out to dry. Or at any moment the company behind a widely used node module could be bought up by another company and their direction could change.
When it comes to stability I personally like to side with Microsoft, for all their faults and I know they can have quite a few, at least you know they'll always be around and they'll run a tight ship when it comes to their developer tools, frameworks and libraries.
Oh boy the big one. Both the Node.js camp and the .NET camp will claim that under certain conditions their framework of choice will outperform the other. There's articles on the web where companies boosted their performance substantially by switching from Node to .NET and vica-versa.
What they don't tell you is the gorey details. How old was their previous codebase, how experienced was the team that developed it, how many stupid mistakes and problems did the project contain and so on and so on.
Both Node.js and .NET are capable of outperforming or underperforming against each other.
I know you're sick of hearing it depends but this point really really lies on the developer or development team. After all a good workman does not blame his tools. Now having said that when both of them are optimally done and allowed to run on the same system, under the same workload.
BUT keep in mind that unless you are facing heavy traffic and huge request or performance intensive tasks, the difference between the two out in the real world after human error is added to the equation will be miniscule. Only consider performance a metric if you really really have to squeeze out every last % and even then, servers cost a heck of a lot less than developers do per year ;).
Modules & Tools
Node.js has NPM, Dotnet has Nuget. As of 18.Nov.2019 there are apparently
nuget packages and
packages. The numbers are clearly on Node.js' side. However Microsoft develops and maintains a great deal of those packages. When it comes to tooling .NET is the clear winner as it has some of the most powerful and well maintained tools out there.
Visual Studio and Rider spring to mind and lately you can even use Visual Studio code as a full IDE. As of 2019 there is still no official or unofficial Node.js focused IDE, so your best bet will most likely be Visual Studio code with Node.js development plugins.
Both ASP.NET and Node.js can be hosted on Azure, AWS, VPS, Google cloud, Heroku and so on. Once again we are spoiled for choice. However there are more dedicated ASP.NET hosts overall, and with quantity come options.
Async vs Sync
This right here is the key difference between the two. Node.js is fully asynchronous while ASP.NET is synchronous, but allows you to define asynchronous methods.
Basically means that you can only execute a single operationat any given time, meaning that all other operations are blocked until the original operation is fully executed.
Means that you can execute multiple operations at the same time and you do not block other operations during it. Sounds simple enough right? In fact it even sounds like Async is always the way to go.
Hold up there not so fast. Async is great and all but it can cause a ton of headaches when handled improperly. Imagine for a moment that two users submit a request at the same exact time for the same exact code block.
Except user A wants to delete or update the code block and user B wishes to read the code block. This means that user B will either get to see information that should not exist at that moment, he will see old information or will request information that does not exist anymore. 2 wrong results and 1 correct one. I don't like the odds of that.
Furthermore more often than not I had to force synchronicity into my node.js API or webapp for one reason or another. This is why I personally prefer the ASP.NET way of doing it.
The default state of it all is synchronous until async is required.
Heck if you want you can make the entire ASP.NET webapp Async.
As per usual there are no clear winners and the choice boils largely down to personal preference. But I hope that I managed to clear up some things or help you make your decision. Whatever you decide to use, happy coding and let me know about your idea or progress over on twitter you can find me @arctekdev
Subscribe to get your daily round-up of top tech stories!