Should You Start Using Golang Instead of Nodejs

post-title

Someone might use Node.js when they care more about the longer term developer productivity and safety associated with advanced types and functional techniques than every last bit of speed. Of course, to achieve that, they need to use Node.js with TypeScript.

cupofcode nodejs

Speed, simplicity, concurrency, and a statically built binary executable are just some of the commonly cited reasons to choose Go over NodeJS. However, it really goes deeper depending on your needs. Lot’s of developers choose Go for every back end project but the end product is generally a Docker image so choose what you’re most productive in. As someone who regularly uses both Go and NodeJS, I can tell you that almost everyone I have ever met that is equally skilled in both chooses Go. Only people that really don’t have experience with Go choose NodeJS.

In my mind, there is only 1 case: client-side development. Say what you want about the current state of the web, with the myriad of different device types and screen sizes to be supported, HTML and CSS are just plain simple and easy to use. What’s more, now every device honors their styling in some native capacity. You can use a framework called Wails to make Go desktop apps using HTML and CSS. For mobile (but also desktop) PWA’s (Progressive Web Apps) have made it so that you can bypass the app store and just put an app on a user’s device instantly, which is really a website, all in HTML and CSS.

So, where does NodeJS come in?

Well, the dynamic manipulation of HTML and CSS is handled natively by JavaScript. As such, using NodeJS to manage the libraries you may be using for that client-side development makes a lot of sense. For example, if you want to make an app in Angular (this is client/browser side not server/Go side), you STILL will likely need NodeJS’s npm (Node Package Manager), which you can then use to locally install and version manage libraries that you may need/want to use in development.

So, it sounds a bit strange that NodeJS is used on the client side (front end) since it’s understood more as server side language. However, in my mind, this is the best use case for NodeJS. Really, honestly, you just need npm. You likely won’t even touch NodeJS save for npm. For example, if I make an Angular project, I may first install the Angular CLI (ng-cli) with npm and then use that CLI tool for the rest of the project, which in turn uses npm for some things. Missing a dependency/module? No problem, npm to the rescue with a one line install. Again, npm is really all you need as it gives you an easy way to install JavaScript modules/libraries and the package.json it uses is a good way to track your dependencies in source control. In fact, the package.json file can also track separate dependencies just for “dev” work and also can track certain scripts that you can run with npm (i.e. npm start or npm run testfoo). It’s pretty great but again, this is ALL npm at work here only. Bottom line is that at the end of the day, these client-side projects are compiled to a zipped folder of static content: HTML, CSS, and JS. NodeJS is totally out of the picture by the time this deployment/folder is created and has become, in my mind, irrelevant. The greatest treasure that came out of NodeJS is npm.

cupofcode golang

So the conclusion is, if you can learn golang by giving some time to it then you would definitely build applications which will perform better than developed in Node.js. I myself made some backend applications in nodejs then slowly moved to golang and if you use gRPC for communication instead of REST API and GraphQL then you will be at a better place.