LEARNNode CLI Automation

Understanding Node.js

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.

Running JavaScript In Console

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;

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.

Running JavaScript on 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.

JavaSript Terminal

As you can see that I got the answer which is 100. I was able to run JavaScript inside my terminal.

Wrapping Up

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.

Posted by Saad (It's a work in progress: Needs copy editing review by Awais.)