What is Node.js? Tutorials For Beginners - Part 1


what-is-nodejs-cheezycode-image


I have been searching for this answer. Being a .NET developer, I was curious to know what exactly is Node.JS or Node. If we go by the definition on its official website, it says - 

Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.

This definition is not very clear from beginners standpoint. Lets try to understand what's inside Node.JS - 

1. Most of the browsers have some JavaScript Engine working behind the scenes. This engine is the main component of the browser that converts your JavaScript code into machine code. What it actually does is - it takes your JavaScript code, reads it, parses it and then compiles it into machine code. 

2. Chrome has V8 JavaScript Engine, Mozilla has Spider Monkey, Edge has Chakra and Safari has JavaScript Core JavaScript Engine. Every JavaScript engine has its own implementation that is why we face some JavaScript compatibility issues across the browsers.

3. In simple words, we can say that browser is a program which uses JavaScript engine and provides a way to run JavaScript code. i.e. it provides the environment by which you can run JavaScript code. Running JavaScript is not the only task that browser performs. They have additional tasks and features as well. Now let's talk about JavaScript specification. 

4. Each language has some specification i.e. rules and guidelines that it follows. ECMAScript is the specification for scripting languages and JavaScript follows this specification. It has various versions like ECMAScript 2015, ECMAScript 2016 and so on. JavaScript is one of the implementation of these specifications. Browsers are implementing the features specified in these specifications so that we can use latest features in our JavaScript code.

5. But what exactly does this specification covers? It just talks about the language features. You can refer the specification here. Few important questions before we move ahead - 
  • Does it contain how setTimeout should work? 
  • Does it contain how DOM manipulation should work?
  • Does it contain how to fetch data from server?

ANSWER IS NO 😮

Then who is providing the specification for these? Specification for these features is provided by W3C and WHATWG. These features are not part of JavaScript specification.

6. These are the APIs provided by browsers which are "accessed using JavaScript". Here comes another JavaScript incompatibility issue we face. Each browser has its own implementation for this as well. Let me give you one example of incompatibility in DOM Manipulation API - 

remove() is not supported in IE, it has removeNode() method to remove node from the DOM

But wait!! Are we not supposed to talk about NODE.JS 😳 ?

Yes, we are here to understand what is NODE.JS or NODE. But we need to have a clear idea about What is JavaScript ? What are Browser APIs? This will make our understanding clear about Node JS.

Let's summarize all of this - 

JavaScript is a scripting language that follows ECMAScript specification. ECMAScript only specifies language features not the browser APIs. Browser APIs are implemented by the browsers which are accessed via JavaScript. Browser APIs extends the JavaScript syntax to do certain things in the browsers. Browsers provide the environment where you can run your JavaScript and do tasks like - manipulating DOM, fetching data from server, play videos and audio etc. 

This is part 1 of this huge topic. For part 2 - stay tuned.

Happy Reading.

 

Comments

Popular posts from this blog

Just Maths - Views, View Groups and Layouts