Question: What does it mean to say nodeJS is built on the V8 engine?

Question

What does it mean to say nodeJS is built on the V8 engine?

Answers 7
Added at 2016-12-30 17:12
Tags
Question

I'm beginner to MEAN stack, while studying NodeJS, I'm came up with the following statement that's taking my mind

Node.js is a very powerful JavaScript-based framework/platform built on Google Chrome's JavaScript V8 Engine.

but what exactly does it mean by

built on Google Chrome's JavaScript V8 Engine.

and if it's built on Chrome's JS V8 Engine, why does it works on Firefox as well?

Answers
nr: #1 dodano: 2016-12-30 18:12

V8 Engine is an interpreter for Javascript used in Google Chrome.
The statement that NodeJS is built on top of this engine means that it uses this interpreter for it's own thing, so it can also be used on the server, not just in the desktop environment (like in Google Chrome).

NodeJS is a separate application that you can communicate with over the internet, it's like Apache, Nginx or similar, but it's not used for one thing only (like the ones mentioned), but it's mostly used for making web-server like applications.

nr: #2 dodano: 2016-12-30 18:12

Node uses the same JS "engine" that runs chrome. An engine in this case, is a piece of software that compiles, or "translates" your JS code into machine code; or the 0s and 1s your computer can understand. This compilation is a complex process, and there are a few different approaches to solving it, for example google's v8 or mozilla's spidermonkey. Each of these support the entire JS standard (to a certain extent), i.e any JavaScript code can run on them.

When you run a node server, it runs on a machine that acts as a server. The code is not run on the user's machine at all; hence it doesn't matter which browser is used to view your content.

In the MEAN stack, it's angular code that runs on the user's computer. However, it is written in JavaScript, which can be run on any javascript engine.

nr: #3 dodano: 2016-12-30 18:12

Node.js is JavaScript on the server. For example, you can start a Node.js server on http://localhost:8000/, and you can access it with Chrome or Firefox.

Using Node.js (which uses V8), servers can be written in JavaScript rather than PHP or Ruby.

nr: #4 dodano: 2016-12-30 18:12

MEAN stack, reorganized from back to front:

  • MongoDB: data persistence, stores data for later retrieval
  • Node.js: web application server, responds to requests from clients
  • Express: web application framework, reduces Node boilerplate
  • Angular.js: browser framework

So Node.js does not "work on Firefox" (it doesn't work on Google Chrome either): its a server-side technology. Think of it as a replacement for Python/Ruby/Java in that role. So it can/does respond to requests from all sorts of clients (like Google Chrome and Firefox).

What the "built on V8" means is that it uses the same JavaScript interpreter/just-in-time compiler as Google Chrome. But the similarities with chrome pretty much stop there: Node has no rendering engine/css parser/DOM but does have things you need in a server like an HTTP library and a filesystem API.

Also, and I mean no offence: we all started where you are, the fact that you are even asking the question (which again is not a bad thing!) means that building on a stack like MEAN is over your head. The documentation is going to assume that you know things you seem to not know. I strongly recommend furthering your understanding of JavaScript and Node through some tutorials and barebones test apps before trying to through databases and frameworks into the mix.

nr: #5 dodano: 2016-12-30 18:12

Ok let's get through this:

Node.js is a very powerful JavaScript-based framework/platform built on Google Chrome's JavaScript V8 Engine.

JavaScript is a programming language used in internet browsers. It was invented in 1995 by NetScape, I think, and has been submitted to a certification organization called ECMA in 1996.

ECMA has taken the original idea of JavaScript and made a standard called ECMAScript which each JavaScript implementation should follow. You see, JavaScript is not a language that just exists somewhere in the ether - each internet browser comes with it's own implementation of the language - this means that JavaScript usually only works in internet browsers such as Mozilla, Safari, Opera or Chrome for example. (Internet Explorer also comes with an implementation of ECMAScript but they call it JScript for licensing reasons I believe)

The implementation of JavaScript that comes with Google Chrome runs on the powerful V8 engine which is written in a language called C++. V8 interprets your JavaScript code and provides it all the variable types, manages memory etc. The great thing about V8 is that it is open-source and can be embedded in any other C++ program.

So the creators of Node had the idea of taking V8 and enhancing it by adding features that a server needs to serve websites - reading files, responding to requests, routing etc. This means that it is now possible to program the server-side implementation of a website using JavaScript thanks to the Node.js application that interprets your code and essentially translates it to C++ and later machine code further down the line. The important distinction is that Node.js DOES NOT run in your browser! It runs on a server much like when you code the back-end using PHP and apache.

nr: #6 dodano: 2016-12-30 18:12

In order for a programming language to be executed by a computer, it needs to be translated into a format the machine can understand (generally termed machine code). Javascript is no different. When your browser is presented with Javascript code on a website, something needs to compile or, in the case of Javascript, interpret the instructions into machine code.

V8 is the program that was developed by Google to do exactly that. When you use Chrome and it detects Javascript on a page, it passes it to V8 to run the compilation and then your computer executes the resulting code.

V8 was open sourced by Google. The creator of Node, Ryan Dahl, modified the source code so that V8 could be used outside of Chrome and inside an operating system like Linux or MacOS. That is what is meant by your first quote.

The important thing to note here is that you do not execute your Node programs in a browser but rather with the actual computer you are using. There's no correlation between V8 and Firefox, Safari, IE, etc. All of those browsers have their own Javascript interpreters.

nr: #7 dodano: 2016-12-30 19:12

Actually NodeJS is cross platform server side framework. You might know as it is best suited for I/O bound and Data Streaming Applications, it uses Google Chrome's JavaScript V8 Engine for above mentioned purposes So it's independent of browser and platform.

Source Show
◀ Wstecz