What is Node.js and how to set it up?

Node.js is an open-source, cross-platform, JavaScript runtime environment that executes JavaScript code outside of a web browser. Confusing? Let me put it into simple words, Node.js is used to run JavaScript outside the browser.

How to set it up

Having trouble understanding the Node.js? Don't be scared you will understand when you start using it.

Pre-Requisites:

To use Node you must type command-line instructions, so you need to be comfortable with (or at least know how to start) a command-line tool like the Windows Command Prompt, PowerShell, Cygwin, or the Git shell (which is installed along with Github for Windows).

Installation Steps:

Step 1

Go to https://nodejs.org/en/download/ and download it. I would recommend .msi

Step 2

Once downloaded follow the simple steps to install it, the default settings would work just fine.

Step 3

Open command prompt in Windows.

Step 4

Make a new directory using command mkdir name go to it.

Step 5

Type command npm init Name it and default settings would work the rest. Node will setup your environment for you.

Step 6

Open your folder in your favorite editor, mine is VS code.

Step 7

In package.json, to scripts add "Start": "node index"

Step 8

Type some test code in your index.js file. Example console.log("hello")

Last Step:

Type node index command on your command prompt. Voila! you just ran your first JavaScript program outside the browser.


Here is a simple JavaScript program you can use!