DEV Community

Why Go for Node.js Developers

jorin on December 14, 2017

The following is not an attempt to convince anyone that one technology is better than the other, instead I like to explore the strong points of eac...
Collapse
 
orask profile image
Oras Al-Kubaisi

Good read, thank you for taking the time to write it and link to different sources. I totally agree with the point of there is no right or wrong answer and its totally dependant on the software and priorities.

Collapse
 
orkon profile image
Alex Rudenko

Have you tried the tools which compile a node program into a binary? i.e. which package Node and your program into a single executable? For example, github.com/zeit/pkg It does not solve the size problem (about 45 Mb, in my case) and the startup time. But it might be easier to distribute.

Collapse
 
jorinvo profile image
jorin

Yes, pkg is great! Good that you mention it!

Collapse
 
hrmny profile image
Leah

In rust you could use

let to_ints = |s_vec| s_vec.iter().map(|s| s.parse::<i64>().unwrap_or_default(0)).collect::<Vec<_>>();
println!("{?:}", to_ints(vec!["1","2"]));
Collapse
 
bgadrian profile image
Adrian B.G.

I agree and I also took the same path. Writing node apps and realized that Go is a good complementary language, I see them playing well together as in keeping the most business logic in JS and the fast ops in Go.

Collapse
 
sammyisa profile image
Sammy Israwi • Edited

On my Laptop the JavaScript process uses 8.6MB while the Go one uses 380KB

Quick question, how can you tell how much memory each process uses? And why do you think Node uses so much more memory in this case?

Collapse
 
jorinvo profile image
jorin • Edited

Easiest way to see the resource usage of a process is to open Activity Monitor on Mac or Task Manager on Windows.

The memory usage of Node.js is surprising low if you think about how much the environment is doing for you. The runtime translates your code to actual machine code on the fly and while your program is running, it is still being analyzed and optimized so that hot code paths become more efficient and so on.
Everything you have with a compiled language like Go in the separate build step, the VM in a language like JavaScript is doing for you at runtime.

Hope this helps a bit. If you are interested there are many interesting talks and articles about the internals of JavaScript (and other) engines, for example this one: youtube.com/watch?v=p-iiEDtpy6I

Collapse
 
philmod profile image
Philippe Modard

You should use an alpine version of the node docker base image, it will be way lighter. Maybe github.com/mhart/alpine-node

Collapse
 
jorinvo profile image
jorin

Yes, I mentioned that above already. You only need to be aware of all the gotcha that come with not using a full blown distro like Debian or Ubuntu.

Collapse
 
philmod profile image
Philippe Modard

What are these gotchas?

Thread Thread
 
jorinvo profile image
jorin

I do like alpine and recommend everyone giving it a try, but if people already have a complicated setup running on another system, it will be a lot of work to port it. You need to find out how to install all the dependencies you are using, deal with differing versions and varying configuration files. And there will be hard to figure out little differences when you - for example - need to compile some C dependency and can't figure out why it's not working with the C toolchain on that system.
Still, give it a try, maybe you don't have any problems with your setup. Docker image size is also not such a big problem if you use a lot of the same images and they can be reused.

Collapse
 
jorinvo profile image
jorin

More interesting thoughts on which images you want to choose: derickbailey.com/2017/05/31/how-a-...

Collapse
 
coolgoose profile image
Alexandru Bucur

Technically, you can have 'threads' in node.js like github.com/andywer/threads.js or github.com/audreyt/node-webworker-...

Now imho, if you want to do an experiment regarding performance and test something else than node, you can try kotlin since it has decent JS interop kotlinlang.org/docs/reference/js-i...

Collapse
 
lluismf profile image
Lluís Josep Martínez

Does Go have an IDE comparable to those of NET/Java ecosystems?

Collapse
 
jorinvo profile image
jorin • Edited

If you like IDEs, Goland by JetBrains is pretty good. jetbrains.com/go

But Editor Integration is also good with Go. Many people like to use Visual Studio Code. A lot of Go users are using Vim too.

Collapse
 
equan profile image
Equan P.

i think there is a project called Nexus.js now that use threads. Maybe you ever compare it with Go? Great article by the way.

Collapse
 
jorinvo profile image
jorin

Thanks, Nexus looks interesting! Let's see how it goes. Seems to be still pretty new.

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
jorinvo profile image
jorin

It's pretty efficient, but it has to pause the program a bit. In all but the most extreme cases you won't notice the break through.
They even parallelize GC.