What is javascript runtime..? [duplicate] - javascript

This question already has answers here:
In JavaScript, what code executes at runtime and what code executes at parsetime?
(5 answers)
Closed 7 years ago.
As per the definition mentioned on https://nodejs.org/
Node.js is a platform built on Chrome's JavaScript run-time for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
Can any one please help me understand what the JavaScript run-time exactly means?

Maybe it's referring to Google's V8 engine.
It is an engine for processing JavaScript in the browser and is used by Google Chrome.
It's open source.
And it's written in C++.
It works on several platforms including mobile and embedded devices.
For more information see: https://code.google.com/p/v8/
If you google for "chrome javascript runtime", you will get all these links to V8.

Chrome's javascript runtime is Google's V8 engine which was developed by Google to be used with Google Chrome.
It compiles the javascript code to native machine code instead of interpreting bytecode which gives a major performance boost to javascript (which is traditionally very slow compared to other high level languages).
Node.js contains libuv to handle asynchronous events. V8 provides the run-time for JavaScript.

It is a virtual machine which interprets and executes JavaScript mostly on browser. In fact Node.js is a javascript runtime based library.

The JavaScript Runtime (JsRT) APIs provide a way for desktop, Windows Store, and server-side applications running on the Windows operating system to add scripting capabilities to an app by using the standards-based Chakra JavaScript engine that is also utilized by Microsoft Edge and Internet Explorer. These APIs are available on Windows 10 and any version of the Windows operating system that has Internet Explorer version 11.0 installed on the machine.

Related

I got some questions while studying nodejs. Could you please help me?

I got some questions while studying nodejs.
Does nodejs support all Java scripts? The official document says it uses the latest v8 engine. I don't think all JavaScript engines will be supported because they follow the JavaScript used by the v8 engine.
How can I update to the latest v8 engine while using the old version nodejs?
When implementing and running a server using nodejs express or nestjs, which portion of memory does most of the time occupy? I thought it would take up the most memory as soon as I build it.
Does nodejs support all Java scripts? The official document says it uses the latest v8 engine. I don't think all JavaScript engines will be supported because they follow the JavaScript used by the v8 engine.
All spec-compliant JS engines implement the same language specification, so the fact that Node uses V8 doesn't matter for this question. (This is very similar to how all (modern) browsers support the same JavaScript.)
How can I update to the latest v8 engine while using the old version nodejs?
You can't.
Sometimes, there is a bit of wiggle room (e.g. early Node 14.x releases used V8 8.1, later 14.x releases updated to V8 8.4), but you couldn't just take e.g. an old Node 10.x build and stick V8 9.2 into it.
And as Bergi says: just update Node.
What accounts for the most memory when implementing and running a server using nodejs Express or nestjs?
That totally depends on how you write your server.
Once you observe a problem (whether it's memory, or performance, or something else), profile it to figure out what's going on.

How are some Javascript features implemented differently between nodejs and the browser?

According to the v8 wikipedia link:
V8 is intended to be used both in a browser and as a standalone
high-performance engine that can be integrated into independent
projects. V8 is used in the following software:
Google Chrome and all other Chromium-based web browsers, including Brave, Opera and Vivaldi ...
Node.js runtime environment
That in mind - nodejs is also using libuv to handle asynchronous events:
Node.js uses libuv to handle asynchronous events. Libuv is an
abstraction layer for network and file system functionality on both
Windows and POSIX-based systems such as Linux, macOS, OSS on NonStop,
and Unix.
Since both browsers and nodejs share common parts which are not part of the web api or nodes own api.
I assume that some features, which could be done with libuv -
are implemented differently from the the browser.
What are some examples of API/JS implementations that are different between the two?
Quoting from here
Libuv is the library that provides the event loop to Node.js
So basically this answer should give you an idea I suppose.

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

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?
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 throw databases and frameworks into the mix.
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.
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.
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.
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.
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.
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.

Windows 8 Metro Interface - Is it IE10?

I've started playing with Windows 8 recently, and (as a web developer) I'm using JavaScript to build my Metro-style app.
I've learned how to use the debugging tools in VS Express 2012... but it occurs to me that the wrapping WebView (or whatever it's called) could simply be a stripped-down IE10.
I've never heard an explanation for what the HTML/JS engine is in this environment. Does anyone know what is happening under the hood?
This is correct. The rendering of Windows 8 WinRT apps built with XAML is handled by XAML and the ones being built using JS/HTML/CSS are rendering using an IE10's HTML rendering engine and IE10's JavaScript engine.
This is the main reason why IE10 is the only browser that currently implements CSS3 grid layout.
For debugging information on Windows Store Apps written using JavaScript/HTML/CSS:
There is a runtime DOM inspector provided by VS, there is Expression Blend where you can also run the app and there is the native VS debugger. However there is no tool like the IE10 developer tools. The intellitrace should give you enough networking information needed for debugging.
If you look in the Details tab of your Task Manager while you have a Windows 8 HTML/JS app running, you'll see a process called WWAHost.exe. That process is hosting the Trident (HTML/CSS) and Chakra (JavaScript) engines and running the app. The IE10 browser on your machine uses the same engine. There are a few differences between the way apps behave versus websites, however, and you can see those here.

Looking for a Javascript engine, outside of the Webkit

Do pardon the simplicity of the question: mother Google seems not to the have the answer to this one ...
So Java has Rhino, a Javascript engine written in Java. Is there a similarly shaped library out there for processing JavaScript in a Cocoa-touch environment? To be specific - this means not using the UIWebView.
On this (old) page, there’s mention of a bridge between SpiderMonkey (Mozilla’s C-based Javascript engine) and Objective-C. Maybe that’s something to explore?
Besides, isn’t JavascriptCore the iPhone’s javascript engine?
Lastly, perhaps this is what you’re looking for?
http://parmanoir.com/Taming_JavascriptCore_within_and_without_WebView
Perhaps the Google V8 JavaScript Engine could be built for iOS? It seems to build on Linux/ARM so iOS (Darwin/ARM), theoretically, couldn't be too far off =)
Webkit is a web browser engine. So, techincally any JavaScript interpreter/compiler is "outside of the Webkit".
V8 is used in Google Chrome (which uses Webkit) and Node.js, SquirrelFish Extreme is used in Safari (which uses Webkit), SpiderMonkey for Mozilla Firefox, and Chakra for IE9. Take your pick.

Categories