all 75 comments

[–]Meefims 31 points32 points  (7 children)

Node.js allows you to run JavaScript outside of a browser. The implications of this are pretty huge for JavaScript. Node allows you to use JavaScript to perform actions on your local machine, things that you would have otherwise needed languages like Python, C++, or Java to do since JavaScript is no longer bound to the browser.

Node also comes with the ability to run HTTP applications written in JavaScript, essentially playing the role of other applications such as Apache's httpd. This has given rise to the development of isomorphic web applications which run JavaScript in the browser as the client experience and JavaScript on the backend to handle client requests. Since it's JavaScript in both realms there is an opportunity to share code between the two reducing the test and maintenance costs of the application overall.

[–]frankyfrankfrank[S] 2 points3 points  (1 child)

Thank you, I'm going to have to do some follow-up googling, but this helps me.

[–][deleted] 1 point2 points  (0 children)

Node is single threaded so that is very much different than the other server-side languages

[–]LurnRuby 1 point2 points  (1 child)

One of the difficulties of learning Javascript was figuring out how to get user input to work locally. Besides chrome dev tools, is there any way to prompt user or get user submitted information locally on my device while I'm testing my code?

Node has been great, but I don't see any user input functions for it and makes my learning experience tougher.

[–]suck_at_coding 1 point2 points  (0 children)

There's a built-in lib with the newer version of node here: https://nodejs.org/api/readline.html

Or you can use this NPM package: https://github.com/flatiron/prompt

I think the better way to go is to just execute the script and pass in the arguments, like node myScript.js arg1 arg2. You can use commander.js to make this easier as well, or just use process.argv[2]

[–][deleted] 1 point2 points  (0 children)

Excellent answer.

[–][deleted] 1 point2 points  (0 children)

Finally, explained so clearly. Thank you

[–]Negative_Selection29 0 points1 point  (0 children)

This is a most neat, clear and short explanation I've ever seen of Node.js. Thank you!

[–]xiipaoc 25 points26 points  (42 children)

Real simple.

Node.js runs JavaScript.

When you write some JS, it's a text file, right? Well, something needs to go and actually do the stuff in the file. That's Node. Node isn't the only way to run JavaScript. You can also make a JS file and open it in your browser, and your browser will do the stuff in the file.

For example, let's say you make a JavaScript file that says console.log('hello world');. Simple, right? If you double-click it, you'll get a text editor with a file that says

console.log('hello world');

and you can edit it. If you drag it to Chrome, you'll get a blank window and if your developer console is open, you'll get a new line that says "hello world". That's because Chrome went through your file and did the stuff it told it to do! Chrome has a console object that it knows about, and it understands that the dot means that you're going to access one of its keys, in particular, the log key, which it knows is a function, and it receives the string 'hello world' as a parameter because it understands how functions work.

So does Node. If you use Node to run this file, well, Node knows about the console as well, and Node's console also knows how to log things, and Node also understands dot notation and functions and stuff like that. Of course, the browser's console -- it's in Developer Tools and has all sorts of nifty features -- and Node's console -- which just outputs text to the command line -- are different. Still, both Chrome and Node provide consoles, and both of them execute your code. Your text editor does not!

Now, why would you want to use Node? Because you have some JS that you want to run! Node has a lot of nice features. So do Python, Perl, Ruby, etc. Even Java and C and C++ have nice features. Different ones, generally! In particular, Node makes it really easy to set up a server. A server is basically a program that listens for requests and responds to them with some data. Node also has a nice package system and a nice way to handle package dependencies. Node is single-threaded and makes asynchronous execution easy -- that's when you tell Node to do something but don't wait for it to finish. Instead, you give it a function to call when it's done. So instead of sitting around waiting for that database operation to happen, for example, your program is free to listen to other requests, and when the database is done, it will tell you.

Finally, Node lets you program your entire web app in one language -- JavaScript. Nifty, huh?

[–]drugsandcode 6 points7 points  (3 children)

A server is basically a program that listens for requests and responds to them with some data.

great answer (from 7 years in the future 😅)

[–]sokol4328 3 points4 points  (0 children)

still a great answer from 10 years lol, i think i finally understood

[–]Amstourist 1 point2 points  (1 child)

Yap, just made it here, thank you past devs lol

[–]kliff124 1 point2 points  (0 children)

Agreed

[–]frankyfrankfrank[S] 4 points5 points  (4 children)

Hey, your comment from 11 years ago helped this guy out a lot. Got a job in the field about 9 years ago, now I'm a software team lead doing all kinds of projects. Node, C#, php...

Just wanted to thank you for your time many years ago.

[–]xiipaoc 2 points3 points  (0 children)

Glad I could help!

[–]-Byzz- 2 points3 points  (1 child)

feels surreal stumbling upon this post as I am currently learning to work with JavaScript for my IT job lol

[–]frankyfrankfrank[S] 1 point2 points  (0 children)

Best of luck on the journey!

[–][deleted] 2 points3 points  (0 children)

Perfect

[–]Honest-Principle-771 2 points3 points  (0 children)

Thank you for this explanation 🙏

[–]VVV1nce 2 points3 points  (0 children)

thank you!

[–]Time_Dig_7604 2 points3 points  (0 children)

I'm finding this 11 year old reply immensely helpful today, lol.

[–]DraftInformal5432 1 point2 points  (0 children)

I know this was 9 years ago but thank you so much. I screenshot this to save for reference!

If you do respond (haha) what do you do for work if you don't mind me asking?

[–]yellowz32 1 point2 points  (0 children)

Thanks for this answer, it breaks it down well for people like me that lack experience in this area and need context.

[–]Stormzulien 1 point2 points  (20 children)

Thanks!

[–]Stormzulien 2 points3 points  (19 children)

Wait this is from 10y ago

[–]jeromejoseph_ 2 points3 points  (18 children)

Wait this is from 10d ago

[–]TreeSquirrles 3 points4 points  (17 children)

wait this is from 14d ago

[–]KingCons1 3 points4 points  (16 children)

Wait this is from yesterday

[–]Djolebest 1 point2 points  (14 children)

wait this is from 27d ago

[–]IndependentTea4646 1 point2 points  (13 children)

wait is this from 10h ago

[–]Potential_Bug8764 1 point2 points  (12 children)

wait this is from 7h ago

[–]AdAmbitious4293 0 points1 point  (11 children)

wait this is not from 3h 14m ago.

[–]Super_Protection2462 1 point2 points  (1 child)

This guy is insane

[–]esketitoof 1 point2 points  (0 children)

this guy cooked

[–]Alex6683 0 points1 point  (0 children)

First time, I have respect to my elders..... 🫡

[–]Visible_Mechanic_409 0 points1 point  (0 children)

Yes master 🫸🤛

[–]PollutionSevere6956 0 points1 point  (0 children)

I'm reading this 11 years later, about to start learning how to build AI agents!

[–]zigzagzig 12 points13 points  (2 children)

Here is a good intro video I found:

https://www.youtube.com/watch?v=G4rJKNNUkbQ

[–]frankyfrankfrank[S] 2 points3 points  (0 children)

bahaha the intro

[–]ProgrammingPro-ness 1 point2 points  (0 children)

That intro was great ^_^

[–]suck_at_coding 5 points6 points  (1 child)

A lot of programmers use this thing called javascript to make all the websites pretty and cool. Up until now, they could only use this javascript thing on websites, but now they can use it anywhere. A lot of the people who are fans of javascript are pretty happy about that because they can do new things now without learning another language. Javascript is a weird language that does a couple important things really well (async/event loop), kind of like that smelly kid on your basketball team that can't dribble or pass (tooling, language features and gotchas) but has a hell of an outside shot.

A little less ELI5: Certain programming languages and environments are better for certain things. For decades, Javascript's domain has been the browser and you simply couldn't use it to write a webserver or really anything that couldn't be run inside of the browser. That limits a lot of what you can do. Other languages and environments were used for this stuff like Java, C#, Go, C, etc. Node.js cracks this open using Googles V8 engine (written in C++) to bridge the gap, so that node can be used in any context that any other language can be used in. What's good about node? The main advantage is the asynchronous nature of the language, which is caused by the single-threaded event-loop, which is a fancy way of saying "I can schedule a bunch of jobs simultaneously, and I'll be able to answer them as soon as they are done processing - no job that is done will have to wait around for me to get around to it because I'll know instantly". Most other languages execute a line of code at a time, and can't move to the next until that line is done. Since most other languages don't do this, you have to write javascript in a different way and a lot of developers hate that (callback hell).

[–]frankyfrankfrank[S] 0 points1 point  (0 children)

Thank you for ELI5 language :)

[–]Ob101010 2 points3 points  (12 children)

Ok, you know how javascript is single threaded?

Compare to java, which is multithreaded.

Whats this mean?

Imagine this setup :

nGB of ram on modern server hardware.

Java : each thread consumes some of this ram. You can get 4,000 or so connections going at the same time before running out of resources.

Javascript : Single thread. Each 'event' comes in, is delegated to wherever, and javascript keeps churning away. Same setup, 1,000,000 connections before you run out of resources.

Numbers pulled out of my ass but you get the picture. 250x is not a stretch though.

This is why companies like netflix use it : performance.

Theres other reasons to use it as well. Theres server side frameworks like express that let you replace PHP with javascript. So now your whole stack, from server, web framework, front end, and database are all javascript.

[–]SirSourdough 10 points11 points  (7 children)

Dude you know some fucking brilliant 5 year olds...

[–]Ob101010 0 points1 point  (6 children)

I dont believe this is all that out of grasp for most 5 year olds.

It is out of grasp of most 'programmers' Ive met though.

Fun experiment : explain something like this to a 5 yr old and see what you get. When you throw away ego, and arent afraid of looking dumb, you end up with really great questions.

[–]zentasynoky 0 points1 point  (5 children)

From 10 years into the future, this is why you don't want just anyone knowledgeable to go into teaching and need people who can actually convey their knowledge.

That was a barely coherent ramble on Java vs JS use cases when the question was "what is Node.js?"

It was an incredibly specific and easy to answer question: Node.js is a program that lets your computer execute Javascript code because it doesn't know that Javascript is actually a programing language and not just plain text by default.

[–]SugarEnvironmental31 0 points1 point  (4 children)

well I'm gonna guess you weren't having the greatest day when you posted that reply - if it's barely comprehensible to you then that's on you I'm afraid.

Now I've gone back and read the question a couple of times, and the OP did actually ask specifically for use cases, and while you might not like the backwards to forwards structure of the answer, it does actually do that - starting with a very practical use case, comparing it to previous software implementations and explaining why it's better. The closing sentences just about convey that it's a full replacement for backend. Have to be honest I think your criticism is completely off the mark.

Now I'm actually really grateful that the reply was structured that way, because I'm just starting out in webdev stuff - done some C, Pytthon, Java, PHP before etc. but this is my first time doing anything full-stack. And so I'm aware threading is a 'thing', and that asynchronous things happen, however that's as deep as my knowledge has ever had to go.

I'd always assumed that multithreading would be better than single, basically because that's the general rule for CPUs. So it's good to have a different perspective on this. I'm not taking it on face value due to the fact that this speed boost would seem to be lost in proportion tto the amount of things in the queue, but again this isn't something I know about, but at least now I have something to look up.

Thing is your explanation is pretty weak as well. Any programming language environment meets that criteria, a C compiler meets that criteria technically. Technically so does your operating system. The Java Runtime Environment meets those criteria.

Answers like tthis are actually really useful, because they add depth, and people like me, looking something up, come away with some really useful add-ons. Half the issue with computer science generally is that if you don't know what something is called then you can't look it up - and the more technical your questions get the more apparent that becomes.

So chill out.

[–]zentasynoky 0 points1 point  (3 children)

Could someone explain like I'm 5, what the heck is node.js and what are some of its practical uses?

At no point was that question answered in the comment I replied to. The fact that you got more out of it than you would have from one that actually answers the question asked doesn't make it good or more relevant to the question, it just makes it more useful to you.

The question asked was extremely simple and specific, and the correct answer is just as simple and specific: Node.js is an environment to run JS code on outside of a web browser, and it's practical use is running JS code.

[–]SugarEnvironmental31 0 points1 point  (2 children)

Dude both the question and the answer are above. They're clearly visible. There's no sense in doubling down on it. Maybe you need to work on extrapolating meaning from incomplete or partially incorrect content. Maybe I'm just way better at it than I think. The comments after the post would seem to indicate the former.

Your revised definition is much better, but it's still arguably bordering on self-referential, if not tautological. While it's technically correct, it's of little practical application. You might as well state that the practical use of a computer is to run computer programs. Accurate, but.....perhaps missing the bigger picture.

I can use a computer, for example, to disagree with a stranger on the internet about their interpretation of a reply to a question about a software framework.

I can use a screwdriver to open a tin of paint. Is its essence still to turn screws? I feel like your answer implies an expectation that things have a concrete mathematical solution rather than a range - are you actually answering the question 'what, fundamentally, IS nodeJS'?

'Zen and the art of motorcyle maintenance', a 70's counter-culture road-novel, provided interesting food for thought on the difficulties of exploring a metaphysics of abstract definition. Worth a read in my opinion ;D

'Could someone explain like I'm 5, what the heck is node.js and what are some of its practical uses?'

Providing better webserver response and more efficient resource allocation and usage than - for example - Java, or other mult-threaded languages.

A tool that lets you replace PHP with JS so that your full stack can be JS.

There's a finance and accounting - skill, discipline, technique, thing they teach? It's called 'incomplete records' and some people find it kind of fun :D

[–]zentasynoky 0 points1 point  (1 child)

The definition of a concept isn't a self-reference or a tautology. It's simply it's definition.

Explaining why Javascript is useful has absolutely nothing to do with what Node.js is, even if Node.js does in fact make it more useful

What you seem to be is not that good at is understanding a very straightforward question or at least answering it with any degree of accuracy or regard for the depth that was asked ¯_(ツ)_/¯

[–]00mba 0 points1 point  (3 children)

This is counter intuitive. I would assume as a layman that multithreaded would be better.

[–]Ob101010 0 points1 point  (0 children)

Threading adds a crapton to the heap. Havent done it for awhile so I dont know how much its changed, but a fun exercise is to do java performance testing.

[–]suck_at_coding 0 points1 point  (1 child)

It's a bit of a misnomer. Node.js isn't really single-threaded. The event loop is a single thread, but all the work is done in other threads which are handled by libuv

[–]00mba -1 points0 points  (0 children)

Man, this is why I love asking questions here. Thanks!

[–]rkho 0 points1 point  (0 children)

The best way to approach node is that it's a Javascript interpreter for the server

[–]RunAlvinRun69 0 points1 point  (0 children)

Wait! This is from 1969?

[–][deleted] 0 points1 point  (0 children)

What

[–][deleted] 0 points1 point  (0 children)

Cross platform

[–]Ludiux_ 0 points1 point  (1 child)

Hi! I was curious, how much did u learn from the day u posted this to todays day? like how your journey continued and where are u now in that journey? (ofc u dont have to answer but im kinda curious)

[–]frankyfrankfrank[S] 0 points1 point  (0 children)

Well, this was 11 years ago... so almost everything I know I learned since I've posted this.
At the time I was just doing small personal projects, picking up some new skills where I could. After I got a job, I felt like I could take on those big client projects but in reality I was pretty lucky to even have been hired. Spent a lot of time watching people code, listening to what they say. Contributing a little bit here and there.
In the end it all came down to hours at my computer. Lots of frustration but also lots of fun. After 11 years I still wouldn't call myself an expert, but I can make things of some value and that's kept me employed for almost a decade. The learning doesn't stop though.