If you are familiar with JavaScript and have been working with it for quite some time then you probably have heard about Node.js. It is a JavaScript runtime built on top of the Chrome V8 engine. It allows you to run JavaScript on your backend. Let’s see how Node.js works.
You can easily run JavaScript on your console. All you need to do is right-click on any webpage and select the console tab from Chrome or your browser’s Developer Tools. So go ahead and do that.
Once you have opened it, just put down the following piece of code there and see the magic.
const sq = x => x * x;sq(10);
That is how simple and easy it is to run your JavaScript code on a console. Now let’s do the same thing but instead of console, we are going to use a terminal.
So with Node.js, you can actually run JavaScript on your terminal. All you need to do is type node and press Enter. It will initiate the node REPL.
REPL stands for Read, Evaluate, Print, Loop. If you want to run JavaScript on the terminal then you need to enable it first.
By typing node, you have enabled node REPL and you will find yourself inside JavaScript runtime. Now just copy-paste the above piece of code in your terminal and see what happens.
As you can see that I got the answer which is 100. I was able to run JavaScript inside my terminal.
Node.js allows you to create a server, write backend JavaScript code, run your JavaScript code outside of the browser, and much more. It basically ensures that you have all the things you need to develop a powerful Node.js-based application.