What is node js?

Bennison J
YavarTechWorks
Published in
4 min readDec 8, 2022
Basics of nodejs

👉 Hi friends, I am Bennison. I want to start this blog with one question, How do we run our JavaScript file outside of the browser?, each browser has an inbuild JS engine. A JS engine is a computer program that executes the JavaScript code.

  • For example, Google uses the V8 engine to run javascript files, Mozilla firefox uses spider monkey, and safari uses apple’s engine.
  • The answer is, using node we can run javascript outside of our browser.

History Of NodeJs

  • In 1995 Netscape browser introduced Javascript. the first version of JavaScript was created by Brendon Eich at Netscape.
  • In 2008 Google introduced its google browser with the V8 JavaScript engine. this V8 engine is a new JavaScript engine. it allows javascript execution really fast.
  • In 2009 Rayan Dall created the node, it is a JavaScript run-time built on chrome’s V8 JavaScript engine.

NodeJs Runtime

  • Node is a JavaScript runtime, it is not a programming language, and it is not a framework. it is a runtime.
  • Node is a JavaScript environment it allows us to run javascript, and do some extra operations.
  • Using node we can read files, and access the database. and run the code that is not part of JavaScript.
  • When the javascript file runs in the node runtime if some code is not part of the javascript. then node js going to communicate with the LIBUV library.
  • LIBUV is a multiplatform C library that provides supports asynchronous I/O (input/output) operation based on the event loop.

Node REPL

  • We can run Javascript in our terminal, and this mode is called REPL.
  • REPL, which stands for READ, EVALUATE, PRINT, LOOP.
  • READ — first this shell read the line from the code and also parses the code. parsing means, the V8 engine break down our line of code and understand the role of the different part of the line.
const STR = 'Hello' + 'World';
  • In the above string is going to execute, first, it will understand ‘Hello’ is the string, and ‘world’ is another string, and we have a plus sign where these strings are being concatenated. and we have an equal sign, it stores the right side value in the left side variable name.
  • EVALUATE — this parsed code will then run and evaluated by V8. which will give the result of a line.
  • PRINT — finally the result will be printed to the console (in our terminal)
  • LOOP — Once the read, evaluate, and print, this process is done. again this is looping which means again the process is start with ‘READ’.

NodeJs and LIBUV

  • You know, all programs are run in the call stack, which is the execution context of the program.
  • In JavaScript also, the file is run in the call stack. whenever it finds something like node binding I/O operation, these things are handled by LIBUV not node. node doesn’t care about this operation and doesn’t wait till that process is done.
Inside of the nodejs
  • In the above image, we can see fs, HTTP, and path. these are the extra functions in node js. some of the node js APIs are written in javascript and some of the APIs are written in low-level languages like C and C++.
  • Through the node js binding node will argue to the LIBUV which will communicate with the operating system. and finally operating system performs the task.
  • This is how nodes give the task to the operating system. and our node program or Javascript doesn’t wait until the task was done by the operating system. this is called asynchronous I/O (input/output).
  • In node, LIBUV is used to working with the file system and making requests over the network. and over the internet.

👉 I hope this blog has been helpful, In my upcoming blog we can see how the asynchronous operations are handled by node js (non-blocking I/O). Thanks for reading this blog. If you have any doubts you can ask me via Twitter, Linkedin or you can respond on medium.

--

--

Bennison J
YavarTechWorks

👩‍💻 Software Engineer 🚀 UNIX/Linux ♥️ | JavaScript/Node.js 🔥 | SQL 📊 | Backend Developer 💻 | Tech Blogger ✍️ | Tech Enthusiast 🌟 |Continuous Learner 📚