Original text: medium.com/codezillas/…

Nodejs is a runtime or Javascript code runtime environment, while Golang is a programming language but not just for back-end development. Golang was invented by Google in 2007. Nodejs lets Javascript code run on the server, while Golang is suited for server-side writing. Nodejs code is just Javascript code, so it inherits a lot of Javascript features. Javascript is so popular these days that the ECMAScript standard is primarily progressive rather than disruptive. Golang can be considered an evolution from more conservative languages such as C/C ++. Golang’s core structure is built on the basic principles of C and Python.

We’ll take a look at the pros and cons of Golang versus Nodejs to give you a better idea of who to choose for your next project.

performance

  • Golang: Similar performance features to C/C ++, which is pretty good.

  • Nodejs: Golang and Nodejs are fairly fair in terms of raw performance. Raw performance — no extra CPU load — Golang and Nodejs are both relatively satisfactory in this respect, but Golang’s actual performance may be better due to various factors affecting server performance at runtime.


concurrent

  • Golang: Golang uses a concurrency model called “Goruntinues”. Goruntinues allows multiple coroutines to run at the same time, easily and reliably completing concurrent tasks.

  • Nodejs: Nodejs is single-threaded, meaning that tasks are executed sequentially. The need to deal with multiple parallel tasks at the same time can lead to some fatal weaknesses at the same time. Javascript allows for the use of event callbacks to handle concurrency, but this is not efficient enough.


scalability

  • Golang: Golang itself is designed for scalability and high concurrency scenarios, so there aren’t too many obstacles.
  • Nodejs: There have been a number of claims from people and companies using Nodejs that Node has problems in massively scaled environments. Maybe Node can fix this problem later.


Development costs

  • Golang: Golang is a relatively new language and has yet to fully catch on, so be prepared for a lot of reading and manual configuration.
  • Nodejs: Nodejs has hundreds of third libraries, thousands of guides, tons of third party platforms. The large Javascript community has been very helpful in recent years, enabling it to accomplish tasks in a variety of real-world scenarios.


Error handling

  • Golang: Golang requires the program to perform regular explicit error checking and return error codes. This may seem difficult, but it’s actually a better way to keep your application consistent, which makes it more reliable.
  • Nodejs: Nodejs uses a throw/catch model that is triggered immediately to catch errors when they occur. This is a more traditional approach to error handling, and many programming languages use the same approach. So the consistency of the application is a little bit lacking.

print

Golang: go version go1.10 linux/amd64

The Node js: – v9.4.0

After comparing All aspects of Golang and Nodejs, it’s hard to say which one is better than the other, they both have their own strengths and weaknesses. Golang seems to be more reliable than Nodejs in terms of performance, but at the same time you need to compare it in terms of project size, project structure, and business type.


Translators supplement

This part is not owned by the original text, and the translated content does not represent my own views. However, the original text is popular on Medium, so I translated it for everyone to discuss. I myself have been a Nodejs and front-end developer for over 3 years, and have recently been practicing some back-end projects with Golang on and off for a few months. I really like the flexibility of Nodejs/Javascript, although this is one of the things that many people criticize. In addition, the concurrency comparison mentioned in this article only refers to THE Js callback and does not mention the event loop. Although Nodejs is single-threaded, the event loop is efficient enough to handle concurrency. But on the other hand, Golang’s Go Rutines design with Channel is indeed very efficient in concurrency. Because it is not single-threaded, it will also lead to problems of shared resource competition and concurrency safety, forcing me to pay attention to and deal with and consider more situations in actual use. It can also expose you to more operating system or lower-level knowledge and concepts rather than CRUD. I think both Nodejs and Golang have their strengths. My advice is that Golang is a great choice if you are a Nodejs backend engineer who wants to learn a static language on the side, and want to work at a lower level and get familiar with high concurrency scenarios.