Node.js to Golang

Node.js から Golang へ

This article talks in brief about the experience in developing web applications using JavaScript(Using Node.js based Framework) and Golang.
The conclusions I draw here are my personal opinions and I am quite sure there are other developers out there who will think differently about these technologies.

As the title of this article Node.js to Golang indicates, there are issues with Node.js that developers face, which leaves them frustrated and in search for other languages/frameworks solving those issues. Lately, there have been a lot of criticism about using Node.js in high-performance networked applications. This has lead to many developers switching to Golang.

JavaScript and Node.js

JavaScript と Node.js

Javascript, is a high-level, dynamic, weakly typed, prototype-based, multi-paradigm, and interpreted programming language.
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. V8 is Google's open source high-performance JavaScript engine, written in C++ and used in Google Chrome, the open source browser from Google, and in Node.js, among others.
JavaScriptは、高レベルの・動的な・型が弱く・プロトタイプベースで・マルチパラダイムである・インタプリタ型の性質を持つ言語です。Node.jsは、Chrome V8のJavaScript実行エンジンとして使われています。V8とは、オープンソースでハイパフォーマンスなJavaScriptエンジンで、C++で書かれており、Google Chrome(Googleの開発するOSSのブラウザ)などで使われています。

Javascript is a dynamically-typed language and hence is a much easier learning curve. As Node.js is written in JavaScript, it inherits most of the properties of that language. JavaScript is so popular these days that the ECMAScript standard development is done at a very rapid pace.

This has some negative effects for JavaScript and Node.js development:
- It often causes issues relating to backward-compatibility.
- Rapid development can lead to a messier language design compared to languages that integrate features cleanly into their design. A good example of this is concurrent computing with JS. JS best practices for concurrent computing went from a concurrency API (using event-based callbacks), to the development of promises, to the coming support for async generators. These days callback hell is still a serious issue with many Node.js applications. This in turn causes less slower developer progress and a lot of bugs.
- 後方互換で課題が生じることがあります
- 言語が高速な進化は、他のクリーンな設計の言語に比べるとやや、乱雑になることがあります。良い例は、JSを利用した並行プログラミングです。JSの並列処理の方法は、コールバック、Prosise、Asyncといったように進化しています。Node.jsを用いた場合に、いわゆるコールバック地獄がまだ残ることもあります。結果的に、バグが多く・開発が遅くなることもあります。
But even with these issues, JS still has a huge user base. A lot of great applications are built everyday with Node.js.


Go is a programming language created at Google[12] in 2009. It is a compiled, statically typed language in the tradition of Algol and C, with garbage collection, limited structural typing, memory safety features and CSP-style concurrent programming features added.
Golangは、2009年にGoogleが開発した言語です。コンパイル型、静的 型付(Algol/C)、GC、制限された構造型、メモリ安全性、CSPスタイルの並行プログラミングなどがGolangの特徴です。
Go makes it much easier to write robust, networked applications, without sacrificing much in the way of performance, compared to C or C++.
Go improves upon some of the misgivings of those languages:
- Poor dependency management
- Cumbersome type systems
- Difficult memory management
- Lack of parallel computation support
- Lack of multi-core support
- 貧弱な依存性管理
- 面倒な型付け
- メモリ管理の難しさ
- 並行処理の欠如
- マルチコアサポートの欠如
Go also reduces the amount of code typing needed by being more expressive than C or C++.

The high performance is in large part due to the static compilation of the statically-typed Go code. A lot of optimizations are possible when a compiler can do all the code inspection work beforehand, as opposed to the dynamic JS compiler work done during runtime.

Node.js vs Golang

Although Go and Node.js have their differences when it comes to which programming paradigms they enable to be easier, they both have unique and supportive followings. One area where Node.js outshines Go is in the sheer size of their package library and community. Node.js package manager (NPM), the largest package registry in the world, has over 410,000 packages growing at an alarming rate of 555 new packages per day. That number may seem staggering (and it is), however, something to keep in mind is that many of these packages are redundant and/or non-production quality. In contrast, Go has about 130,000 packages.

Although Node.js and Go are around the same age, JavaScript is more widely used — boasting a large development and open-source community. This is of course because Node.js was developed for the general public with a robust package manager from the start while Go was specifically built for Google.

Node.js Go
Performance Due to JS's dynamically-typed nature, Node.js can not reach the raw performance of CPU or memory bound tasks that Go can achieve in many tests. However, in the common use cases where network communication or database interaction are involved, the performance of Node.js and Go are often equal. Similar performance characteristics as with C or C++, which is to say very good.
Concurrency Node.js suffers from JavaScript's less than elegant concurrency support using the event-callback mechanism. However, for a lot of applications, working with JS promises and the coming async generator support. Go uses coroutines called goroutines. A goroutine is a lightweight thread managed by the Go runtime. Communication between goroutines is done very elegantly using channels.
Scalability Node.js was never created to solve the compute scaling problem. It was created to solve the I/O scaling problem. Any CPU intensive computation will block Node.js responsiveness, so a threaded platform is a better approach. (* By Node.js Foundation) Go was really designed for scalability and concurrency, without too much hassle.
Ease of Development For a JS developer, it is really easy to get into Node.js programming. People coming from a JS/Node.js background will need to learn some new programming concepts, such as: coroutines, channels, strict typing (with compilation), interfaces, structs, pointers, and some other differences.
Node.js Go
パフォーマンス 動的型付の性質より、Node.jsはGolangよりCPUバウンドやメモリバウンドなパフォーマンスで劣ります。しかし、ネットワーク/データベースを使う処理が含まれるアプリケーションの場合、Node.jsやGolangのパフォーマンスはほぼ同様です。 C/C++と同様で非常に良いです。
並列性 コールバックを用いる処理の場合は、エレガントな並列処理のサポートとは言えません。しかし、多くにアプリケーションではPromiseおよびAsyncでよりエレガントに書けます。 Goはゴールーチンという仕組みを使います。ゴールーチンは、Goのランタイムに管理される軽量スレッドです。ゴールーチン間のコミュニケーションは、チャネルによってエレガントに実現されています。
スケーラビリティ Node.jsは計算処理のスケーラビリティの課題を解決するようには、デザインされていません。どちらかというと、I/Oのスケーラビリティ課題を解決することに狙いを置いています。CPUインテンシブな計算処理は、Node.jsの応答性をブロックすることがあります。その場合は、スレッド処理の方が良いアプローチになるでしょう。(* By Node.js Foundation) Golangはスケーラビリティと並列性向けに非常に適しています。
開発の簡単さ JSの開発者であれば、Node.jsのプログラミングを始めるのは簡単です。 JS/Node.jsをバックグランドに持つ開発者にとっては、新しいプログラミングコンセプトを学ぶ必要があります。たとえば、コルーチン・チャネル・型付け(コンパイル)・インターフェース・構造体・ポインタなどです。



This post is not to prove that one language is better than another. Every programming language has its place in the software development community for one reason or another. The intentions were to highlight the differences between Go and Node.js, as well as promote exposure to a new web development language. When choosing a language for a given project, there are a lot of different factors to consider including developer familiarity, cost, and practicality. I encourage a thorough low-level analysis when deciding what language is right for you.

As we have seen, there are several benefits to Go. The raw performance, simple syntax, and relatively shallow learning curve make it ideal for scalable and secure web applications. With its fast growth in adoption and community involvement, there is no reason Go can't become a prominent player in modern web development. That being said, I believe that Node.js is moving in the right direction to remain a powerful and useful language if implemented correctly. It has a large following and active community that makes it a simple platform for getting a web application up and running in no time.

Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.