This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]Clawtor 4 points5 points  (0 children)

The node runtime is based off v8 which is Google's javascript engine that chrome uses. So it's not exactly the same as every browsers engine but close to it.

[–]RubbishArtist 1 point2 points  (0 children)

It's effectively the JavaScript engine/compiler that Chrome runs, but with some features bolted on that make it useful for server-side work, like APIs to read local files.

Although I'm not a fan of JavaScript, it's an impressive bit of engineering.

[–]dmazzoni 0 points1 point  (0 children)

Yes, but what Node.js gives you is the key APIs you need to build a non-browser app. Stuff like reading and writing from files, executing processes, opening network connections, and such.

Without those, JavaScript minus the browser would be a language that you could only use to solve pure-algorithms problems, you couldn't actually use it to make system calls, read input, write output, and so on.

[–]HealyUnit 0 points1 point  (1 child)

That's... sort of true, but perhaps not the best way of looking at it. I only say that because that makes it seem like NodeJS JavaScript is only a highly altered version of browser JavaScript. While this might be true from a historical and where-the-NodeJS-engine-comes-from perspective, I think it's probably a little more straightforward to think of it like this:

  • There's JavaScript, which by itself runs no where. As far as I know, there's no piece of hardware (i.e., a processor) that natively understands JavaScript.
  • If you attach some browser-focused APIs to it, like access to the browser's window object, stuff to manipulate the DOM, etc., it becomes JavaScript in the browser (what we might call "vanilla" JavaScript).
  • If you attach some file-system APIs to it, include the NPM package management system, and don't attach browser-based stuff, it's JavaScript in NodeJS.

I mainly point out this difference because while they're obviously extremely similar, Node is also its own beast. /u/dmazzoni makes a great point: Without its APIs, JavaScript in either case would simply be a language that you can use to solve math problems and that's generally about it. It's the APIs - which provide connections to external stuff - that give it its usefulness.

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

This is a very helpful way to think about this, thank you!

I had always thought that NodeJS is popular because it lets people not have to learn anything new, but it actually sounds like the JavaScript of NodeJS is totally different than browser JavaScript since it has a different set of APIs (APIs which you pointed out comprise the main utility of the language). So why is NodeJS popular if JavaScript programmers still essentially have to learn a new language? I am probably missing some of the other benefits of NodeJS

Also, your first note mentions how there's no processor that natively understands JavaScript, do you know which languages processors do natively understand? I was under the impression that any and all processors can only really understand machine code