Java Script On Server

Java Script On Server

What is a Server ?

  • It is a type of system that handles requests from clients and provides services, data, or resources over a network.

  • Example : web server like Apache which hosts websites and serves web pages to user's browsers when they request them via the internet.

What it means when we say we are running a website on server ?

  • Tt means that the website's files, such as HTML, CSS, images, and scripts, are hosted on a server, which responds to requests from users' browsers by delivering the website's content over the internet. The server processes these requests, allowing the website to be accessible to users online.

  • In other words it is one CPU or a machine which is receiving the requests and processes these requests.

Relation of Java Script and Server ?

  • Initially Java Script was the only language which was used inside the browser but after Node-JS we can run Java Script on the server.

  • Now Java Script coming on the server as well as the web it gave us an opportunity for a single developer to develop Full Stack Applications.

  • Java Script engineers can now code using libraries and frameworks like React and Angular on the client side and using Node-JS on the server side.

Does Node-JS has C++ code ?

  • Yes Node-JS includes C++ code. Node-JS is built on top of the V8 Java Script engine which is written in C++.

  • Node.JS uses C++ for certain performance-critical parts of its runtime.

What is V8 Java Script engine ?

  • The V8 engine is an open-source Java Script engine developed by Google, primarily used in the Chrome browser and Node-JS to execute Java Script code. In other words V8 is Google's open source high performance Java Script and web assembly engine written in C++.

  • V8 is written in C++. The Java Script Engine uses C++ to execute Java Script Code. 72% majority of the code of V8 is written in C++.

  • The Job of V8 Engine is to execute Java Script Code.

  • V8 can be embedded into any C++ application.

  • We write Java Script code then it is being read by V8 which is written in C++ converts the code in which machine understands.

  • V8 engine follows ECMA Script standards.

What is ECMA Script ?

  • It is standard for Scripting language including Java Script, JS script and Action Script.

  • All JS engine must follow ECMA Script.

Does Node JS has V8 embedded on it ?

  • Yes, Node.JS has the V8 JavaScript engine embedded within it.

  • When we install Node.JS, the V8 engine comes bundled with it. This means that when we run a Node-JS application, our JavaScript code is executed directly by the V8 engine.

When V8 executes any piece of Java Script code why was there need of Node-JS ?

  • V8 is the engine that executes Java Script code, Node-JS provides the runtime environment for the use JavaScript for server-side development.

  • Node JS has V8 engine plus it has a lot more super powers.

  • Node-JS essentially empowers Java Script to be used as a general-purpose programming language outside of the browser.

  • Node-JS as a C++ program it has V8 embedded in it and along with that there are more super powers which it gives and when it runs on the server makes it very powerful.

What are these super powers of Node-JS ?

  • This can be explained by example , suppose if we have a data base installed and if we want to connect to the data base through Java Script or let us take another example if we want to make HTTP call then these super powers comes inform of API and that is the core thing that Node-JS adds onto V8

  • Node-JS with these super powers on top of V8 and this is known as Java Script runtime.

  • Node-JS : Java Script (62%) + C++(21%).

Java Script run time ?

  • A Java Script runtime is an environment that allows Java Script code to be executed,. It includes JavaScript Engine, APIs , Event Loop: and Call Stack.

  • In other words a Java Script runtime provides everything needed to execute Java Script code and interact with the environment in which it runs, whether that's a browser (like Chrome) or a server (like Node.js).

Is V8 written in C++ ?

  • Yes, V8 is written in C++. The V8 Java Script engine is a high-performance engine developed by Google, and it’s primarily written in C++

  • Computers only understands Binary Code. On top of Binary code there is Assembly code and on top of Assembly code there is High level language. C++ is a high level language.

  • These C++ code or the Java Script engine takes our Java Script code converts it into a machine code and machine code converts it to a low level code. Machine Code plus Assembly Code is known as low level code.

  • The code that we write in the higher languages and we need a C++ program or something like a JS Engine that converts our high level code to machine understandable code, which is the job of JS Engine.

  • In other words, V8 is a C++ based engine designed to execute Java Script code efficiently by compiling it to machine code.