DEV Community

Discussion on: Explain nodejs to me like Im five

Collapse
 
jochemstoel profile image
Jochem Stoel

Javascript is the language used in browsers to enable dynamic stuff/interaction. By dynamic I mean interactive. Not a static page but things can happen like popups and color changes and sliding menus.
Because Javascript is a very nice language to work with and a lot of people are using it, they have decided to use this same language on the server side of things. Here the same language is used for things that happen on the server. (like database connection for login)
A major cool thing is that the browser and the server have no trouble understanding eachother because they speak the same language. It is also very resource efficient. That means it is fast and does not need a lot of memory.
Node.js is a program that is a standalone Javascript language interpreter. It is the same Javascript interpreter the Chrome browser uses. It is made in such a way that it can run on almost any computer. Node simplifies it for developers like us by having done that already. That is why Node is awesomesauce.

I can't possibly simplify this more sorry :P my brain hurts now.

Collapse
 
kspeakman profile image
Kasey Speakman • Edited

I like your explanation except for this bit:

Because Javascript is a very nice language to work with ...

It's getting there, but still has a ways to go. I think the "because" probably has more to do with it being basically zero steps to start using (open a browser console (F12) and start typing), and it is the only viable option for browser-based apps. Whether they love it or hate it, web developers are required to know some Javascript. The other options that now exist still "compile" to Javascript.

WebAssembly may one day allow us to develop web front-ends in any language without touching Javascript.

Then when you start with Javascript, at some point you have to communicate with a backend to do things like save to database. A lot of back-end techs are intimidating to get into. You have to learn (potentially a lot) of incidental platform knowledge to even get started. Node came in and made it relatively simple to get started on the back end too, additionally so by using a language familiar to every web developer, Javascript. For developers who get into development via web or who work heavily with web front-ends, Node.js is a natural choice for a back-end.

Even if you don't use it for a back-end, web developers probably have Node.js installed for all the tools available via npm to build their web front-ends.

Collapse
 
jochemstoel profile image
Jochem Stoel • Edited

Although I was being sarcastic when I wrote that Javascript is a very nice language, I do actually stand behind this. Yeah you're right, it's getting there but so is everything else. I am very satisfied with the (not so) recent (anymore) developments of the language we have come to love and implement and the people responsible for it have done a great job adjusting to the requirements of modern browsers and even completely other realms Javascript was not expected to ever appear.

Javascript is universal. There are small context specific implementations sure but overall nearly everything can be ported from one realm to the other. Javascript can be typed procedurally and static as well as the most absurd high level abstraction design patterns because it is a script language without a lot of 'rules' on how to approach something. This freedom we have created a lot of 'styles' over time which I like to personally refer to as dialects. Which dialect you prefer and choose to use is up to you.

A good example of this is that a few years ago people started writing their event handler register function as on(). In stead of object.addEventListener('click', function() { }) we started doing object.on('click', ...). To some people this is blashphemy, to me it is beauty. Where else do you find code that is this semantic?

Another thing to love about Javascript is the collaborative effort. It is by far the most 'social' language in the sense that we are all constantly influencing its direction by the code we write and share with the world daily and the proposals we make for future syntax. I have my own preferences and dialect and sometimes I see other people copying my methods in often completely different contexts. There is no other language where you can see the origin, cause and effect so clearly.

We can use Javascript to write low level backends and interactive frontends using the same interpreter. Besides, even though there are multiple interpreters out there (V8, NiL, etc) they all do their best to have identical implementations rather than competing who gets to be right.

Then there is Electron/NW.js/app.js, the various crap like React and Express and don't get me started on super sets like TypeScript.

And yes, like you said even without acknowledging all this, the NPM ecosystem is still the largest one in the world and that has a reason.

OK. I will stop here I can go on for hours I think I might have a problem. Thanks for commenting on my post, it is really motivating to communicate with somebody about stuff like this.

Thread Thread
 
nhsz profile image
Nicolás Quiroz • Edited

Besides familiarity with the language if you've been on web dev before, I think the main "selling point" of NodeJS for devs is that it was able to greatly simplify the problem of concurrency. You have only one thread available so you forget to deal with threads and all that stuff.

Of course you now have to deal with other problems, i.e.: callback hell and async thinking.

Resource efficiency (hence lower costs) and scalability is the other one.

Thread Thread
 
jochemstoel profile image
Jochem Stoel

I would like you to elaborate on the problem of concurrency. What practical problem did this solve for you? What were you struggling with every day that Node solved by being single threaded? Do you even know why it is single threaded? I am very curious because the majority of web developers that are considered competent have zero understanding of this.

Thread Thread
 
nhsz profile image
Nicolás Quiroz

I mean, you don't have to deal with multiple threads like you do if you're working with other server-side languages.

Multi-threading is hard, like sharing data between threads. If you are working with server-side web programming in PHP, Java, Python, etc you will have to deal with it unless you have very low traffic APIs or services.

I think Go's approach to concurrency with "light threads" and goroutines is better than the async model though, but Node's was quite clever.

Thread Thread
 
jochemstoel profile image
Jochem Stoel

I think I have never reached any point where I needed to deal with multi-threading when I was writing something in for instance PHP. I suspect that I do this all the time.

Collapse
 
neuron profile image
Kekayan

Thank you :) .